-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove.js
51 lines (42 loc) · 1.37 KB
/
move.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
40
41
42
43
44
45
46
47
48
49
50
51
function getStyle(obj,name)
{
if(obj.currentStyle)
{
return obj.currentStyle[name];
}
else{
return getComputedStyle(obj,false)[name];
}
}
function startMove(obj,attr,iTarget)
{
clearInterval(obj.timer);
obj.timer=setInterval(function(){
//开一个定时器30ms
var cur=0;
if(attr=="opacity")
{
cur=Math.round(parseFloat(getStyle(obj,attr))*100);
}
else{
cur=parseInt(getStyle(obj,attr));
}
var speed=(iTarget-cur)/6;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(cur==iTarget)
{
clearInterval(obj.timer);
}
else{
if(attr=="opacity")
{
obj.style.filter='alpha(opacity('+(cur+speed)+')';
obj.style.opacity=(cur+speed)/100;
document.getElementById('txt1').value=obj.style.opacity;
}
else{
obj.style[attr]=cur+speed+'px';
}
}
},30)
};