[英]Element scroll is not working to load more data from db
我有這段代碼用於在元素上使用垂直滾動加載一些數據,但是如果我更改'div [data-tk =“ or”] .data .datadivmain'以證明它正在工作,但它不起作用,但是我想使用元素滾動。 有什么想法嗎?
$('div[data-tk="or"] .data .datadivmain').scroll(function(e) {
// grab the scroll amount and the window height
var scrollAmount = $('div[data-tk="or"] .data .datadivmain').scrollTop();
console.log('scroll position amount:', scrollAmount);
var documentHeight = $(document).height();
// calculate the percentage the user has scrolled down the page
var scrollPercent = (scrollAmount / documentHeight) * 100;
if (scrollPercent > 30) {
var main_data = $('div[data-tk="or"] .data .datadivmain');
$(new_data).children().appendTo(main_data);
$(Dahlia.V.currentPage.main + " .nex a").click();
}
});
問題是加載代碼,盡管我已經添加了文檔,但是它仍然無法正常工作,因此我使用了setTimeout
函數,並且現在可以正常工作。
setTimeout(function() {
var new_data = $('div[data-tk="ro"] .data .datadiv');
new_data.css('display', 'none');
$('div[data-tk="ro"] .data .pagination ,div[data-tk="ro"] .data .listcount').css('display', 'none');
var datadivmain = $("<div></div>").addClass("datadivmain");
datadivmain.css({ 'overflow-y': 'auto', 'height': '500px' });
if (!$('div[data-tk="ro"] .data .datadivmain').length > 0) {
datadivmain.insertBefore(new_data);
var main_data = $('div[data-tk="ro"] .data .datadivmain');
$(new_data).children().appendTo(main_data);
}
$('div[data-tk="ro"] .data .datadivmain').scroll(function() {
var main_data = $('div[data-tk="ro"] .data .datadivmain');
// grab the scroll amount and the window height
var scrollAmount = main_data.scrollTop();
var documentHeight = main_data.height();
var full_height = main_data[0].scrollHeight;
// calculate the percentage the user has scrolled down the page
var scrollPercent = (scrollAmount / (full_height - documentHeight)) * 100;
// console.log('full_height', scrollPercent);
if (scrollPercent > 96) {
$(new_data).children().appendTo(main_data);
$(Dahlia.V.currentPage.main + " .nex a").click();
}
});
}, 1000);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.