-
Notifications
You must be signed in to change notification settings - Fork 0
/
scroll.html
67 lines (52 loc) · 1.22 KB
/
scroll.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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title>上拉加载demo</title>
<style>
.box{
width:100%;
background:#666;
}
p {
background: #eee;
padding: 30px 0;
}
</style>
</head>
<body>
<div class="box">
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
</div>
<script src="jquery.min.js"></script>
<script type="text/javascript">
// mock数据
var arr = ['test','test','test','test','test','test','test','test','test','test'];
window.onscroll = function(event){
var screenHeight = window.screen.height;
var scrollHeight = document.documentElement.scrollHeight;
var scrollTop = document.documentElement.scrollTop;
if(scrollHeight - (screenHeight + scrollTop) < 10){
console.log('这是下一页数据');
//下面就是请求下一页数据的逻辑了,自行发挥
var htmlt = '';
for(var i = 0; i < arr.length; i++){
htmlt = htmlt + '<p>' + arr[i] + '</p>';
}
var box = $('.box').html()
$('.box').html(box + htmlt);
}
}
</script>
</body>
</html>