浅谈js的setInterval事件

标签:关于我们    日期:2018-03-26 10:13    录入:汇盛国际平台    浏览:

  
  

  
  
  
  
  
  
  var one=document.getElementById('one')  
  var x=0;  
  var y=0;  
  var xs=10;  
  var ys=10;  
  function scroll(){  
  x+=xs;  
  y+=ys;  
  if(x>=document.getElementById('content').offsetWidth-one.offsetWidth-20 || x<=0)  
  {  
  xs=-1*xs;  
  }  
  if(y>=document.getElementById('content').offsetHeight-one.offsetHeight-20 || y<=0)  
  {  
  ys=-1*ys;  
  }  
  one.style.left=x;  
  one.style.top=y;  
  }  
  dt=setInterval(scroll,100);  
  one.onmouseover=function(){  
  clearInterval(dt);  
  };  
  one.onmouseout=function(){  
  dt=setInterval(scroll,100);  
  };  
  
  

★★★小编:汇盛国际注册 整理文章,欢迎大家转载 ★★★