-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMove.js
47 lines (40 loc) · 1.22 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
function getStyle(obj, name) {
if (obj.currentStyle) {
return obj.currentStyle(name);
} else {
return getComputedStyle(obj, false)[name];
};
};
function Move(obj, json, end) {
clearInterval(obj.time);
var cur = 0;
var speed = 0;
obj.time = setInterval(function () {
var bStop = true;
for (var name in json) {
if (name == 'opacity') {
cur = Math.round(parseFloat(getStyle(obj, name) * 100));
} else {
cur = parseInt(getStyle(obj, name));
};
speed = (json[name] - cur) / 6;
speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
if (cur != json[name]) {
bStop = false;
};
if (bStop == false) {
if (name == 'opacity') {
obj.style.opacity = (cur + speed) /100;
obj.style.filter='alpha(opacity:'+(cur+speed)+')';
} else {
obj.style[name] = cur + speed + 'px';
};
};
};
if (bStop) {
// alert('abc');
clearInterval(obj.time);
end();
};
}, 30);
};