我如何让我的函数重新启动

How do I get my function to restart?

本文关键字:函数 重新启动 我的      更新时间:2023-09-26

加载时自动调用moveit()函数。Moveit()上下移动图像(一行)。我希望这种情况持续发生;但是,我不知道如何使我的功能重新启动。目前,我让页面重新加载每次行到达页面的底部。这需要很多时间,所以我想重新启动这个函数。谢谢!

<html manifest="manifest.appcache">
<body onload="moveit(8)">
<img style="margin: 0 auto;" src="http://media.tumblr.com/593368ddaf4ad655258a076f959856fa/tumblr_inline_mgmuspje6G1re2ao1.bmp"></img>
<style type="text/css">
                .moveimage { position:absolute; right:0; bottom:0; z-index:2 }
}
</style>
<script language="JavaScript">
function moveit(spot)
{
if (document.getElementById("image1"))
  {
   var picture=document.getElementById("image1").style;
      if (spot<328)
      {
        picture.bottom= spot;
        spot+=3.7;
        setTimeout('moveit('+spot+')',15);
       }
      if (spot>328)
      {
                picture.top= spot;
        spot+=1.25;
                setTimeout('moveit('+spot+')',10);
      }
      if (spot>650)
      {
                window.location.reload();
      }
   }
}
</body>
</script>

</html>

修改行

window.location.reload();

picture.bottom = 0; // reset
picture.top = ""; // reset
moveit(); // and start over again

您可以替换这一行:

window.location.reload();

,例如:

setTimeout(function() { moveIt(8); }, 10);

参数8与您在onload处理程序中使用的相同-当然您可以将其设置为任何其他适当的值

此事件处理程序将触发html滚动事件。

$('html').scroll(function(){
//do something
})

您也可以在任何容器上使用overflow:scrolloverflow:auto