-
Notifications
You must be signed in to change notification settings - Fork 0
/
23.链式运动框架.html
65 lines (61 loc) · 1.5 KB
/
23.链式运动框架.html
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
function getStyle(obj, name) {
if(obj.currentStyle) {
return obj.currentStyle[name];
} else {
return getComputedStyle(obj, false)[name];
}
}
function startMove(obj, attr, iTarget,fnEnd) {
clearInterval(obj.timer);
obj.timer = setInterval(function() {
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);
if(fnEnd)fnEnd();
} else {
if(attr == "opacity") {
obj.style.filter = "alpha(opacity:" + (cur + speed) + ")";
obj.style.opacity = (cur + speed) / 100;
} else {
obj.style[attr] = cur + speed + "px";
}
}
}, 30);
}
window.onload=function(){
var oDiv=document.getElementsByTagName("div")[0];
oDiv.onmouseover=function(){
startMove(oDiv,"width",300,function(){
startMove(oDiv,"height",300,function(){
startMove(oDiv,"opacity",100);
})
})
}
}
</script>
<style type="text/css">
div{
width: 100px;
height: 100px;
background: red;
opacity: 0.3;
}
</style>
</head>
<body>
<div></div>
</body>
</html>