-
Notifications
You must be signed in to change notification settings - Fork 0
/
下拉刷新.html
109 lines (103 loc) · 2.82 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Document</title>
<style type="text/css">
html,
body,
header,
div,
main,
p,
span,
ul,
li {
margin: 0;
padding: 0;
}
#refreshContainer li {
background-color: #eee;
margin-bottom: 1px;
padding: 20px 10px;
}
.refreshText {
position: absolute;
width: 100%;
line-height: 50px;
text-align: center;
left: 0;
top: 0;
}
</style>
</head>
<body>
<main>
<p class="refreshText"></p>
<ul id="refreshContainer">
<li>111</li>
<li>222</li>
<li>333</li>
<li>444</li>
<li>555</li>
<li>111</li>
<li>222</li>
<li>333</li>
<li>444</li>
<li>555</li>
<li>111</li>
<li>222</li>
<li>333</li>
<li>444</li>
<li>555</li>
</ul>
</main>
<script type="text/javascript">
(function (window) {
var _element = document.getElementById("refreshContainer"),
_refreshText = document.querySelector(".refreshText"),
_startPos = 0,
_transitionHeight = 0;
console.log("_element:", _element);
console.log("_refreshText:", _refreshText);
_element.addEventListener(
"touchstart",
function (e) {
console.log("初始位置:", e.touches[0].pageY);
_startPos = e.touches[0].pageY;
_element.style.position = "relative";
_element.style.transition = "transform 0s";
console.log(111);
},
false
);
_element.addEventListener(
"touchmove",
function (e) {
console.log("当前位置:", e.touches[0].pageY);
_transitionHeight = e.touches[0].pageY - _startPos;
if (_transitionHeight > 0 && _transitionHeight < 60) {
_refreshText.innerText = "下拉刷新";
_element.style.transform = "translateY(" + _transitionHeight + "px)";
if (_transitionHeight > 55) {
_refreshText.innerText = "释放更新";
}
}
},
false
);
_element.addEventListener(
"touchend",
function (e) {
_element.style.transition = "transform 0.5s ease 1s";
_element.style.transform = "translateY(0px)";
_refreshText.innerText = "更新中...";
// todo...
},
false
);
})(window);
</script>
</body>
</html>