1 var timer=null; 
 2 function startMove() 
 3 { 
 4 
 5 var oDiv=document.getElementById('div1'); 
 6 clearInterval(timer); 
 7 timer=setInterval(function () { 
 8 var iSpeed=1; 
 9 
10 if(oDiv.offsetLeft>=300) 
11 { 
12 clearInterval(timer); 
13 } 
14 else 
15 { 
16 oDiv.style.left=oDiv.offsetLeft+iSpeed+'px'; 
17 } 
18 },30); 
19 }; 

 


缓冲运动: 
 1 var timer=null; 
 2 function startMove() 
 3 { 
 4 var iTarget=300; 
 5 
 6 var oDiv=document.getElementById('div1'); 
 7 
 8 clearInterval(timer); 
 9 timer=setInterval(function () { 
10 var iSpeed=(iTarget-oDiv.offsetLeft)/8; 
11 
12 iSpeed=iSpeed>0?Math.ceil(iSpeed):Math.floor(iSpeed); 
13 
14 iSpeed=Math.ceil(iSpeed); 
15 if(oDiv.offsetLeft==iTarget) 
16 { 
17 clearInterval(timer); 
18 } 
19 else 
20 { 
21 oDiv.style.left=oDiv.offsetLeft+iSpeed+'px'; 
22 } 
23 document.title=oDiv.style.left+' '+iSpeed; 
24 },30); 
25 }; 
这样,一个运动框架就写好了!原理很简单,不过还有待完善。慢慢来吧!

相关文章:

  • 2022-12-23
  • 2022-02-02
  • 2021-12-07
  • 2021-10-31
  • 2021-09-06
  • 2021-06-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-18
  • 2022-12-23
  • 2021-05-05
  • 2021-10-04
  • 2022-12-23
  • 2021-05-20
  • 2018-05-15
相关资源
相似解决方案