0

JavaScript でイベントをdiv使用して Web ページ内を移動する方法。イベントが呼び出されonloadたときにこの動きを停止する必要がありますか?mouse over

<script type="text/javascript">
  var wid=1002;

  var rmax = wid2;
  var tmr  = 10;

  var intg = 2;
  var dir  = 2;

  function moveIt() {
    obj = document.getElementById("d1").style;
    curr = parseInt(obj.left);
    if (curr > rmax) {
      dir = -dir;
    }
    obj.left = curr + dir + "px";
    if ((curr == 0) && (dir < 0)) {
      dir = -dir;
    }
    timer=setTimeout("moveIt()", intg*tmr);
  }

  function init() 
  {
    setTimeout("moveIt()", intg*tmr);
  }

  function stoper() {
    clearTimeout(timer);
  }

  function hideDiv() {
   $(".floatMainContainer").hide();
   $(".floatThankyouContainer").show();
  }
</script>
<body onLoad="init()">
  <div id="d1" style="border:px solid black; top: 2%; left: 0px; z-index:999999; position:absolute; width:262px; height:6px; background-color:none;" onMouseOver="stoper()"   onmouseout="moveIt(),10000" >
    <div class="floatMainContainer"  >
      <span class="close">
        <span>Close</span>
      </span>
    </div>
  </div>
</body>
</html>   
4

1 に答える 1

1

well asuming you tagged this post with jquery, I suppose you use it.

On Load event in jQuery looks like this:

$(function(){ <!-- here you can start moving around your div's as crazy -->   });

To stop them moving (asuming you used jQuery animate to move them) just go:

$(yourDivsClass).mouseover(function(){ $(this).stop(); }
于 2012-09-20T09:50:35.347 に答える