-
Notifications
You must be signed in to change notification settings - Fork 0
/
moveUtil.js
39 lines (37 loc) · 1.03 KB
/
moveUtil.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* Created by CC on 2016/8/16.
*/
function getStyle(obj, attr) {
if (obj.currentStyle) { //ie
return obj.currentStyle[attr];
} else {
return window.getComputedStyle(obj, false)[attr]; //非ie
}
}
function move(element,target,fn){
clearInterval(element.timer);
element.timer=setInterval(function(){
var isComplete=true;
for(var attr in target){
var cur=Math.round(parseFloat(getStyle(element,attr)));
if(!cur){
cur=0;
}
var speed=(target[attr]-cur)/10;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
//speed>0?speed=Math.ceil(speed):speed=Math.floor(speed);
if(cur==target[attr]){
//sclearInterval(timer);
}else{
isComplete=false;
element.style[attr]=cur+speed+"px";
}
}
if(isComplete){
clearInterval(element.timer);
if(fn){
fn();
}
}
},30);
}