I have this code for loading some data using a vertical scrolling on the element but it's not working if I change the 'div[data-tk="or"] .data .datadivmain' to document it's working but I want to use elements scroll. any thought on this?
$('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();
}
});
the issue was with loading codes although I have added that inside the document ready it still was not working so I used the setTimeout
function and it's working now.
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.