VANHIEP.NET - Làm web giá rẻ - Thiết Kế Website - Thiết Kế Ứng Dụng Mobile
Load dữ liệu từ server khi cuộn trang hoặc cuộn nội dung 1 box nào đó [Jquery Ajax]

Load dữ liệu từ server khi cuộn trang hoặc cuộn nội dung 1 box nào đó [Jquery Ajax]

$(window).scroll(function() {
    if($(window).scrollTop() == $(document).height() - $(window).height()) {
           // ajax call get data from server and append to the div
    }
});

Đoạn code điều kiện để load dữ liệu về khi cuộn cửa sổ trình duyệt

 

$('#someScrollingDiv').on('scroll', function() {
    let div = $(this).get(0);
    if(div.scrollTop + div.clientHeight >= div.scrollHeight) {
        // do the lazy loading here
    }
});

Còn đây là đoạn code áp dụng cho 1 khung dữ liệu nào đó trong trang web, ví dụ như 1 box div tin nổi bật ở bên trái hoặc bên phải...