-
Notifications
You must be signed in to change notification settings - Fork 0
/
move1.html
91 lines (86 loc) · 1.64 KB
/
move1.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>运动1</title>
<style type="text/css">
#div_1{
width: 200px;
height: 200px;
background: red;
position: absolute;
left: 0px;
top: 50px;
}
#div_2{
width: 100px;
height: 200px;
background: green;
position: absolute;
left:-100px;
top: 270px;
}
#div_2 span{
width: 20px;
height: 60px;
position: absolute;
left: 100px;
top: 70px;
line-height: 20px;
background: blue;
}
</style>
<script type="text/javascript">
window.onload=function(){
//图片运动,侧穿运动
var oBtn=document.getElementById('button_1');
var oDiv=document.getElementById('div_1');
var oDiv2=document.getElementById('div_2');
var oSpn=document.getElementById('span_1');
var timer=null;
oBtn.onclick=function(){
clearInterval(timer);
timer=setInterval(function(){
if(oDiv.offsetLeft>=300){
clearInterval(timer);
}
else{
oDiv.style.left=oDiv.offsetLeft+7+'px';
}
},30);
}
oDiv2.onmouseover=function(){
startMove(0);
}
oDiv2.onmouseout=function(){
startMove(-100);
}
function startMove(flag){
if(oDiv2.offsetLeft<flag){
speed=10;
}
else{
speed=-10;
}
clearInterval(timer);
timer=setInterval(function(){
if(oDiv2.offsetLeft==flag){
clearInterval(timer);
}
else{
oDiv2.style.left=oDiv2.offsetLeft+speed+'px';
}
},30);
}
}
</script>
</head>
<body>
<input id="button_1" type="button" value="开始运动">
<div id="div_1">
</div>
<div id="div_2">
<span id="span_1">分享到</span>
</div>
</body>
</html>