-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path联系我.html
72 lines (69 loc) · 1.36 KB
/
联系我.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<style>
*{
margin:0;
padding:0;
}
body{
height:2000px;
}
#wrapper{
position:absolute;
width:200px;
height:300px;
background-color: #ccc;
top:200px;
left:-200px;
}
#div{
position:absolute;
width:100px;
height:300px;
right:-100px;
background-color: red;
text-align:center;
line-height:300px;
}
</style>
<body>
<div id="wrapper">
<div id="div">联系我</div>
</div>
<script>
var oDiv = document.getElementById("div");
var oWrapper = document.getElementById("wrapper");
var timer;
window.onscroll = function(e){
e = e || event;
var iScrollTop = document.documentElement.scrollTop || document.body.scrollTop;
console.log(iScrollTop);
oWrapper.style.top = iScrollTop + 200 + "px";
};
oWrapper.onmouseover = function(){
clearInterval(timer);
timer = setInterval(function(){
if(oWrapper.offsetLeft >= 0){
clearInterval(timer);
}else{
oWrapper.style.left = oWrapper.offsetLeft + 10 + "px";
}
},30);
};
oWrapper.onmouseout = function(){
clearInterval(timer);
timer = setInterval(function(){
if(oWrapper.offsetLeft <= -oWrapper.offsetWidth){
clearInterval(timer);
}else{
oWrapper.style.left = oWrapper.offsetLeft - 10 + "px";
}
},30);
};
</script>
</body>
</html>