div 达到特定 PX 时触发事件
您好,如果可以的话,请看一下我的代码,并告诉我下一步要做什么才能得到这个结果。
<script type="text/javascript">
function doMove1() {
foo1.style.left = parseInt(foo1.style.left)+1+'px';
setTimeout(doMove1,20); // call doMove in 20msec
}
function start1() {
foo1 = document.getElementById('fooObject'); // get the "foo" object
foo1.style.left = '0px'; // set its initial position to 0px
doMove1(); // start animating
}
window.onload = start1;
</script>
<body>
<div id="fooObject">
<img src="images/pac.gif" width="38" height="38"></div>
</body>
基本上发生的事情是图像在屏幕上移动。我想要完成的是,当图像达到某个像素(比方说 900px)时,我希望触发一个事件。有关完成此任务的任何提示我是初学者,在我想到寻求帮助之前我已经为此工作了一整天。
Hi If could please take a look at my code and tell me what the next step I am looking for to get this result.
<script type="text/javascript">
function doMove1() {
foo1.style.left = parseInt(foo1.style.left)+1+'px';
setTimeout(doMove1,20); // call doMove in 20msec
}
function start1() {
foo1 = document.getElementById('fooObject'); // get the "foo" object
foo1.style.left = '0px'; // set its initial position to 0px
doMove1(); // start animating
}
window.onload = start1;
</script>
<body>
<div id="fooObject">
<img src="images/pac.gif" width="38" height="38"></div>
</body>
Basically what happens is that a image moves across the screen.What i am trying to accomplish is that when the image gets to a certain px (Lets say 900px) I want an event to fire. Any tips on accomplishing this task I am a beginner Ive been working on this all day before i thought to seek help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需在
doMove1
中添加对此的检查:这有帮助吗?
Just add a check for this in
doMove1
:Does that help?