-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.php
96 lines (69 loc) 路 2.14 KB
/
index.php
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
<?php
include_once 'db.class.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Infinite Scroll</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.min.css">
</head>
<body>
<div class="container">
<br />
<h1>Infinite Scroll</h1>
<br />
<div id="news_area">
<?php
$sql = "select * from news order by news_id desc limit 7";
$query = $db->query($sql);
while($row = $query->fetch(PDO::FETCH_OBJ)){
?>
<div class="alert alert-danger well well-lg " news_id="<?php echo $row->news_id;?>"><?php echo $row->news;?></div>
<?php
}
?>
</div>
<div id="notif"></div>
</div>
<script src="js/jquery-1.11.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
<script>
$(document).ready(function() {
$(window).data('scroll_progress', true).scroll(function(e) {
if ($(window).data('scroll_progress') == false) return;
if($(window).scrollTop() + $(window).height() == $(document).height()) {
var check_end = $("#notif div" ).attr('id');
if(check_end != 'end'){
$( "#notif" ).html('<div class="alert alert-info" role="alert" style="text-align:center">Loading news...</div>');
var last_news_id = $("#news_area div:last-child" ).attr('news_id');
var dataString = { send : true , last_news_id : last_news_id };
$(window).data('scroll_progress', false);
$.ajax({
type: "POST",
url: "loading_news.php",
data: dataString,
dataType: "json",
cache : false,
success: function(data){
$(window).data('scroll_progress', true);
if(data.end == false){
if(last_news_id != data.last_news_id){
$( "#news_area").append(data.news);
$( "#notif" ).html('');
}
} else {
$( "#notif" ).html('<div id="end" class="alert alert-success" role="alert" style="text-align:center">All news loaded</div>');
}
} ,error: function(xhr, status, error) {
alert(error);
},
});
}
}
});
});
</script>