style.right和.style.top选项未更新 [英] style.right and .style.top options not updated in

查看:265
本文介绍了style.right和.style.top选项未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两张照片,一个是轮子,另一个是箭头。

I have two pictures, one of a wheel and another of an arrow. I want to position the arrow so it will point down on the wheel.

在我的身体部分,我定义:

In my body part I defined:

<body onload="g1()">
    <img src="arrow.png" id="arrow" width=8%>
    <br>
    <center>
    <img src="wheel.png" id="wheel">
    <br>
    <h2 style="width:200px;" id="status"></h2>
    </center>
</body>

我的功能如下:

        function g1()
        {
            var left1=screen.width/2;
            var tikli=document.getElementById("arrow");
            //tikli.style.right=0;
            //tikli.style.top=0;
            tikli.style.right=left1;
            tikli.style.top=left1;
            tikli.style.zIndex+=2;
            //rotateAnimation("wheel",8,710);
        }

现在的问题是,.style.right和.style .top正在更新,箭头的位置不是。 (我发现他们是通过插入之间的警报更新)。

Now the problem is, while the values of .style.right and .style.top are being updated, the arrow's position isn't. (I found out they are updated by inserting alerts in between).

我在这里缺少什么?

(ps。上传图片到此处

编辑:
附加CSS脚本:

Attaching CSS script:

<style type="text/css">
        body{
            //font-size:22px;
        }
        #arrow{
            position:absolute;
            bottom:100px;
            right:500px;
        }
</script>


推荐答案

screen.width / 2 ; 将给你一个数字,而不是一个CSS长度。您需要向它添加px

screen.width/2; is going to give you a number, not a CSS length. You need to add "px" to it.

这篇关于style.right和.style.top选项未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆