简体   繁体   English

style.right和.style.top选项未在以下位置更新

[英]style.right and .style.top options not updated in

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>

And my function here is: 我的功能是:

        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);
        }

Now the problem is, while the values of .style.right and .style.top are being updated, the arrow's position isn't. 现在的问题是,虽然正在更新.style.right和.style.top的值,但箭头的位置却没有。 (I found out they are updated by inserting alerts in between). (我发现它们之间通过插入警报进行了更新)。

Am I missing something in here? 我在这里想念东西吗? For the record, I tried it both in Chrome and in IE, and the arrow still doesn't move. 作为记录,我在Chrome和IE中都尝试过,但箭头仍然没有动。

(ps. uploaded the pics to here ) (ps。将图片上传到这里

Edit: Attaching CSS script: 编辑:附加CSS脚本:

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

screen.width/2; is going to give you a number, not a CSS length. 会给你一个数字,而不是CSS长度。 You need to add "px" to it. 您需要添加"px"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM