-
Notifications
You must be signed in to change notification settings - Fork 0
/
缓动.html
46 lines (46 loc) · 872 Bytes
/
缓动.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
div{
width:200px;
height:100px;
background:#d90;
margin-top:20px;
}
</style>
<script>
window.onload=function(){
var div=document.getElementsByTagName("div");
for(var i in div){
div[i].onmouseover=function(){
move(this,800);
}
div[i].onmouseout=function(){
move(this,200);
}
}
var time=null;
function move(obj,target){
clearInterval(obj.time);
obj.time=setInterval(function(){
var speed=(target-obj.offsetWidth)/5;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(obj.offsetWidth==target){
clearInterval(obj.time);
}else{
obj.style.width=obj.offsetWidth+speed+"px";
}
},30);
}
}
</script>
</head>
<body>
<div></div>
<div></div>
<div></div>
</body>
</html>