Skip to content

Commit 19c0616

Browse files
committed
多属性缓冲运动框架
缓冲运动框架
1 parent 0aba00f commit 19c0616

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

bufferMove.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
//获取样式信息
3+
function getStyle(node,attr){ //无法取到复合样式 如:border
4+
if(node.currentStyle){ //IE
5+
return node.currentStyle[attr];
6+
}else{
7+
return getComputedStyle(node,false)[attr];
8+
}
9+
}
10+
11+
//多属性缓冲运动
12+
function bufferMove(obj,json,fn){
13+
clearInterval(obj.timer);
14+
obj.timer = setInterval(function(){
15+
var state = true;
16+
for(var attr in json){
17+
var iCur = 0;
18+
if(attr == 'opacity'){
19+
iCur = parseInt(parseFloat(getStyle(obj,attr))*100);
20+
}else{
21+
iCur = parseInt(getStyle(obj,attr));
22+
}
23+
var iSpeed = (json[attr]-iCur)/8;
24+
iSpeed = iSpeed>0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);
25+
if(iCur != json[attr]){
26+
state = false;
27+
}
28+
if(attr == 'opacity'){
29+
obj.alpha = iCur+iSpeed;
30+
obj.style.filter = 'alpha(opacity:'+obj.alpha+')';
31+
obj.style.opacity = obj.alpha/100;
32+
}else{
33+
obj.style[attr] = iCur+iSpeed+"px";
34+
}
35+
}
36+
if(state){
37+
clearInterval(obj.timer);
38+
if(fn){fn();}
39+
}
40+
},30);
41+
}

0 commit comments

Comments
 (0)