完美运动框架
1 function getByClass(oParent,sClass)
2 {
3 var aEle=document.getElementsByTagName('*');
4 var i=0;
5 var aResult=[];
6
7 for(i=0;i<aEle.length;i++)
8 {
9 if(aEle[i].className==sClass)
10 {
11 aResult.push(aEle[i]);
12 }
13 }
14 return aResult;
15 }
16 function getStyle(obj,attr)
17 {
18 if(obj.currentStyle)
19 {
20 return obj.currentStyle[attr];
21 }
22 else
23 {
24 return getComputedStyle(obj,false)[attr];
25 }
26 }
27 function startMove(obj, attr,iTarget)
28 {
29
30 clearInterval(obj.timer);
31 obj.timer=setInterval(function(){
32 var iCur=0;
33 if(attr=='opacity')
34 {
35 iCur=parseFloat(getStyle(obj,attr))*100;
36 }
37 else
38 {
39 iCur=parseInt(getStyle(obj,attr));
40 }
41 var iSpeed=(iTarget-iCur)/8;
42 iSpeed=iSpeed>0?Math.ceil(iSpeed):Math.floor(iSpeed);
43
44 if(iCur==iTarget)
45 {
46 clearInterval(obj,timer);
47 }
48 else
49 {
50 if(attr=='opacity')
51 {
52 obj.style.filter='alpha(opacity:'+(iCur+iSpeed)+')';
53 obj.style.opacity=(iCur+iSpeed)/100;
54 }
55 else
56 {
57 obj.style[attr]=iCur+iSpeed+'px';
58 }
59 }
60 },30)
61 }