71 lines
1.8 KiB
HTML
71 lines
1.8 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>详情</title>
|
|
<script src="./ajax.js"></script>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="main">
|
|
|
|
</div>
|
|
</body>
|
|
|
|
<script>
|
|
var page = 3,
|
|
id = location.search.split("id=")[1],
|
|
total_page = "";
|
|
|
|
function GetInfoData() {
|
|
ajax({
|
|
url: 'http://192.168.0.109:3000/api/json/info',
|
|
data: {
|
|
id: id,
|
|
page: page
|
|
},
|
|
methods: 'GET',
|
|
async: true,
|
|
success: function (res) {
|
|
total_page = res.total_page
|
|
RenderInfo(res.list)
|
|
},
|
|
error: function (err) {
|
|
console.log(err);
|
|
}
|
|
})
|
|
}
|
|
|
|
function RenderInfo(data) {
|
|
data.forEach(v => {
|
|
document.querySelector(".main").innerHTML += `
|
|
<img src="${v.src}" alt="">
|
|
`
|
|
});
|
|
}
|
|
|
|
|
|
document.querySelector("body").onscroll = function () {
|
|
let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
|
|
let clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
|
|
let scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
|
|
|
|
//避免没有数据的时候 重复执行 scrollHeight > clientHeight
|
|
if (scrollHeight > clientHeight && scrollTop + clientHeight === scrollHeight) {
|
|
console.log("滚动到底部");
|
|
page += 1;
|
|
if (page > total_page) {
|
|
alert("没有数据了...")
|
|
} else {
|
|
GetInfoData()
|
|
}
|
|
}
|
|
}
|
|
|
|
GetInfoData()
|
|
</script>
|
|
|
|
</html> |