-
Notifications
You must be signed in to change notification settings - Fork 6
/
037-多个div缓动效果.html
53 lines (52 loc) · 951 Bytes
/
037-多个div缓动效果.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
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
div{width:100px; height:100px; background:red; margin-top:50px;}
</style>
<script>
window.onload = function()
{
var oDiv1 = document.getElementById("div1");
var aDiv = oDiv1.getElementsByTagName("div");
for(var i = 0; i < aDiv.length; i++)
{
aDiv[i].timer = null;
aDiv[i].onmouseover = function()
{
startMove(this,300);
}
aDiv[i].onmouseout = function()
{
startMove(this,100);
}
}
}
function startMove(obj, iTarget)
{
clearInterval(obj.timer);
obj.timer = setInterval(function(){
var ispeed = (iTarget - obj.offsetWidth) / 8;
ispeed = ispeed > 0 ? Math.ceil(ispeed):Math.floor(ispeed);
if(obj.offsetWidth == iTarget)
{
clearInterval(obj.timer);
}
else
{
obj.style.width = obj.offsetWidth + ispeed + "px";
}
},30);
}
</script>
</head>
<body>
<div id="div1">
<div></div>
<div></div>
<div></div>
</div>
</body>
</html>