1 // JavaScript Document 2 3 function startMove(obj,json,endFn){ 4 5 clearInterval(obj.timer); 6 7 obj.timer = setInterval(function(){ 8 9 var bBtn = true; 10 11 for(var attr in json){ 12 13 var iCur = 0; 14 15 if(attr == ‘opacity‘){ 16 if(Math.round(parseFloat(getStyle(obj,attr))*100)==0){ 17 iCur = Math.round(parseFloat(getStyle(obj,attr))*100); 18 19 } 20 else{ 21 iCur = Math.round(parseFloat(getStyle(obj,attr))*100) || 100; 22 } 23 } 24 else{ 25 iCur = parseInt(getStyle(obj,attr)) || 0; 26 } 27 28 var iSpeed = (json[attr] - iCur)/8; 29 iSpeed = iSpeed >0 ? Math.ceil(iSpeed) : Math.floor(iSpeed); 30 if(iCur!=json[attr]){ 31 bBtn = false; 32 } 33 34 if(attr == ‘opacity‘){ 35 obj.style.filter = ‘alpha(opacity=‘ +(iCur + iSpeed)+ ‘)‘; 36 obj.style.opacity = (iCur + iSpeed)/100; 37 38 } 39 else{ 40 obj.style[attr] = iCur + iSpeed + ‘px‘; 41 } 42 43 44 } 45 46 if(bBtn){ 47 clearInterval(obj.timer); 48 49 if(endFn){ 50 endFn.call(obj); 51 } 52 } 53 54 },30); 55 56 } 57 58 59 function getStyle(obj,attr){ 60 if(obj.currentStyle){ 61 return obj.currentStyle[attr]; 62 } 63 else{ 64 return getComputedStyle(obj,false)[attr]; 65 } 66 } 67 68 function stopMove(obj){ 69 clearInterval(obj.timer); 70 }
JS运动库
时间: 2024-11-05 20:25:58