在页面中有关于运动特效的js效果可以借用该框架
首先先借助之前的获取样式的方法:
```
function getStyle(obj,name){//获取对象的属性名称
if(obj.currentStyle){//IE
return obj.currentStyle[name];
}
else{//非IE
return obj.getComputedStyle(obj,false)[name];
}
```
现在获取到想要的任意对象的属性值
运动框架需要判断属性是否含有透明度:
```
if(目标=='opacity'){
数组=getStyle(obj,目标)*100; //获取的透明度为小数,*100让其转化为整数
}
else(){
数组=parseInt(getStyle(obj,目标));
```
运动的函数:
```
function StartMove(obj,json,fnend){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var on=true;
for(var attr in json){
var cur=0;
if(attr=='opacity'){
cur=getStyle(obj,attr)*100;
}
else{
cur=parseInt(getStyle(obj,attr));
}
var speed=(json[attr]-cur)/10;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(cur!=json[attr]){
on=false;
}
else{
on=ture;
}
if(attr=='opacity'){
obj.style.opacity=(cur+speed)/100;
obj.style.fitler='alpha(opacity'+cur+speed+')';
}
else{
obj.style[attr]=cur+speed+'px';
}
}
if(on){
clearInter(obj.timer)
if(fnend){
fnend();
}
}
},30)
}
```