-
Notifications
You must be signed in to change notification settings - Fork 0
/
move4.html
55 lines (55 loc) · 1.13 KB
/
move4.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>运动4</title>
<style type="text/css">
div{
width: 100px;
height: 50px;
background: red;
margin: 10px;
border: 10px solid black;
}
</style>
<script type="text/javascript">
//多运动变宽
window.onload=function(){
var oDiv=document.getElementsByTagName('div');
for(var i=0; i<oDiv.length; i++){
this.timer=null;
oDiv[i].onmouseover=function(){
startMove(this,500);
}
oDiv[i].onmouseout=function(){
startMove(this,100);
}
}
}
function getStyle(obj,name){
if(obj.currentStyle)
return parseInt(obj.currentStyle[name]);
else
return parseInt(getComputedStyle(obj,false)[name]);
}
function startMove(obj,flag){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var speed=(flag-getStyle(obj,'width'))/6;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(getStyle(obj,'width')==flag){
clearInterval(obj.timer);
}
else{
obj.style.width=getStyle(obj,'width')+speed+'px';
}
},30);
}
</script>
</head>
<body>
<div></div>
<div></div>
<div></div>
</body>
</html>