-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTextindex.html
64 lines (63 loc) · 1.29 KB
/
Textindex.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
<!DOCTYPE html>
<html>
<!--Alt是跳转,Shift是转义,Ctrl是操作。-->
<head>
<title>分享运动</title>
<meta charset="utf-8"/>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
#div1{
width:200px;
height: 300px;
background: royalblue;
left: -200px;
top:50px;
position: relative;
}
#div1 span{
width: 20px;
height: 50px;
background:red;
left: 200px;
top: 50px;
position: absolute;
}
</style>
<script type="text/javascript">
window.onload = function(){
var oDiv=document.getElementById("div1");
oDiv.onmouseover=function() {
starMove(0);
}
oDiv.onmouseout=function(){
starMove(-200);
}
}
var timer=null;
function starMove (iTarget) {
clearInterval(timer);
var oDiv=document.getElementById("div1");
timer = setInterval(function() {
var speed=(iTarget-oDiv.offsetLeft)/10;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
//offsetleft当前值
if (oDiv.offsetLeft==iTarget) {
clearInterval(timer);
}else{
//Math.floor 向下取整!
//Math.ceil向上取整!
oDiv.style.left=oDiv.offsetLeft+speed+'px';
}
},30)
}
</script>
</head>
<body>
<div id="div1">
<span id="share">分享</span>
</div>
</body>
</html>