-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path动画实验.html
68 lines (64 loc) · 1.23 KB
/
动画实验.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
66
67
68
<!doctype html>
<<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>动画实验</title>
</head>
<style type="text/css">
li{
width:200px;
height:50px;
background-color: green;
margin-bottom: 20px;
}
h1{
background-color: transparent;
filter:alpha(opacity=20);
}
</style>
<body>
<ul>
<li id="li1"></li>
</ul>
</body>
<script type="text/javascript">
var ali=document.getElementById('li1');
ali.timer=null;
ali.onmouseover=function(){
move(ali,{height:400},function(){
move(ali,{width:400})
});
};
ali.onmouseout=function(){
move(ali,{height:50},function(){
move(ali,{width:200})
});
};
function move(obj,Json,fn){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
for( name in Json){
var flag=true;
var nowWidth=parseInt(getStyle(obj,name));
var speed=(Json[name]-nowWidth)/10;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(nowWidth!=Json[name])
flag=false;
obj.style[name]=nowWidth+speed+"px";
if(flag){
clearInterval(obj.timer);
if(fn)
fn();
}
}
},30);
}
function getStyle(obj,atrr){
if(obj.currentStyle)
return obj.currentStyle[atrr];
else
return getComputedStyle(obj,false)[atrr];
}
</script>
</html>