使用js将图像从上到下移动以及滚动

时间:2014-08-13 05:11:52

标签: javascript html

此代码工作正常,但图像不依赖于滚动条,图像不会移动滚动条移动,我需要一个标签,使其可以使用滚动条移动.....我想你明白了查询....图像移动顶部到底部,但我用卷轴管理它的运动....它可能我在我的网页上看到它

<html>
<head>
<title>Demo of Image moving across screen in JavaScript</title>
<script language='JavaScript' type='text/JavaScript'>
<!--
function reset1(){
clearTimeout(my_time);
//document.getElementById('i1').style.left= "500px";
document.getElementById('i1').style.top= "100px";
document.getElementById("msg").innerHTML="";

}



function move_img(str) {

var x=document.getElementById('i1').offsetTop;
x= x +100;
document.getElementById('i1').style.top= x + "px";

}

function disp(){
var step=1; // Change this step value
//alert("Hello");
var y=document.getElementById('i1').offsetTop;
//var x=document.getElementById('i1').offsetLeft;
if(y < 600 ){y= y +step;
document.getElementById('i1').style.top= y + "px"; // vertical movment
}//else{
//if(x < 800){x= x +step;
//document.getElementById('i1').style.left= x + "px"; // horizontal movment
//}
////}
//////////////////////

}

function timer(){
disp();
var y=document.getElementById('i1').offsetTop;
var x=document.getElementById('i1').offsetLeft;
//document.getElementById("msg").innerHTML="X: " + x + " Y : " + y
my_time=setTimeout('timer()',10);
}


//-->
</script>
</head>
<body onload="timer()" >
<img src=images/help.jpg id='i1' style="position:absolute;height:200px;width:200px;">
<br><br><br><br>
<div id='msg' style="height:200px;width:300px;"></div>

</body>
</html>

0 个答案:

没有答案
相关问题