Multi timer multi object motion frame

From , 4 Years ago, written in JavaScript, viewed 53 times.
URL https://pastebin.vip/view/311abb49
  1. <!DOCTYPE html>
  2. <html>
  3.         <head>
  4.                 <meta charset="UTF-8">
  5.                 <title>多定时器多物体运动框架</title>
  6.                 <style type="text/css">
  7.                         #div1{
  8.                                 width: 200px;
  9.                                 height: 200px;
  10.                                 background: yellow;
  11.                                 margin: 10px;
  12.                                 float: left;
  13.                         }
  14.                                 #div2{
  15.                                 width: 200px;
  16.                                 height: 200px;
  17.                                 background: yellow;
  18.                                 margin: 10px;
  19.                                 float: left;
  20.                         }
  21.                 </style>
  22.         </head>
  23.         <body>
  24.                 <div id="div1">变宽</div>
  25.                 <div id="div2">变高</div>
  26.                 <script type="text/javascript">
  27.                         window.onload=function(){
  28.                                 var oDiv1=document.getElementById('div1');
  29.                                 oDiv1.onmouseover=function(){
  30.                                         startMove1(this,400);
  31.                                 }
  32.                                 oDiv1.onmouseout=function(){
  33.                                         startMove1(this,200);
  34.                                 }
  35.                                 var oDiv2=document.getElementById('div2');
  36.                                 oDiv2.onmouseover=function(){
  37.                                         startMove2(this,400);
  38.                                 }
  39.                                 oDiv2.onmouseout=function(){
  40.                                         startMove2(this,200);
  41.                                 }
  42.                         }
  43.                        
  44.                        
  45.                         function startMove1(obj,iTarget){
  46.                                 clearInterval(obj.timer);
  47.                                 obj.timer=setInterval(function(){
  48.                                         speed=(iTarget-obj.offsetWidth)/6;
  49.                                         speed=speed>0?Math.ceil(speed):Math.floor(speed);
  50.                                         if(obj.offsetWidth==iTarget){
  51.                                                 clearInterval(obj.timer);
  52.                                         }else{
  53.                                                 obj.style.width=obj.offsetWidth+speed+'px';
  54.                                         }
  55.                                 },30);
  56.                         }
  57.                            
  58.                                 function startMove2(obj,iTarget){
  59.                                 clearInterval(obj.timer);
  60.                                 obj.timer=setInterval(function(){
  61.                                         speed=(iTarget-obj.offsetHeight)/6;
  62.                                         speed=speed>0?Math.ceil(speed):Math.floor(speed);
  63.                                         if(obj.offsetHeight==iTarget){
  64.                                                 clearInterval(obj.timer);
  65.                                         }else{
  66.                                                 obj.style.height=obj.offsetHeight+speed+'px';
  67.                                         }
  68.                                 },30);
  69.                         }      
  70.                 </script>      
  71.         </body>
  72. </html>

Reply to "Multi timer multi object motion frame"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website