This commit is contained in:
@@ -43,6 +43,7 @@ class Search {
|
||||
let input = $(".header input")
|
||||
|
||||
$(".header .button").onclick = async () => {
|
||||
this.page = 1
|
||||
if (input.value.length != 0) {
|
||||
this.keyword = input.value
|
||||
this.totalArr = []
|
||||
@@ -51,7 +52,13 @@ class Search {
|
||||
util.hidden(".no-search")
|
||||
item(".have-search ul", this.totalArr)
|
||||
util.show(".have-search")
|
||||
this.onscroll()
|
||||
onscroll(async () => {
|
||||
this.page += 1
|
||||
if (this.page <= this.totalPage) {
|
||||
await this.getSearchKeyData()
|
||||
item(".have-search ul", this.totalArr)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
@@ -75,23 +82,6 @@ class Search {
|
||||
this.totalPage = totalPage
|
||||
list.forEach(v => this.totalArr.push(v));
|
||||
}
|
||||
|
||||
// 滚动到底部实现自动加载下一页数据
|
||||
onscroll() {
|
||||
window.onscroll = async () => {
|
||||
var scrollHeight = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
|
||||
var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
|
||||
var clientHeight = window.innerHeight || Math.min(document.documentElement.clientHeight, document.body.clientHeight);
|
||||
|
||||
if (clientHeight + Math.ceil(scrollTop) >= scrollHeight) {
|
||||
this.page += 1
|
||||
if (this.page <= this.totalPage) {
|
||||
await this.getSearchKeyData()
|
||||
item(".have-search ul", this.totalArr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new Search
|
||||
Reference in New Issue
Block a user