Home > Web Front-end > JS Tutorial > body text

jQuery method to dynamically load content when the page is scrolled_jquery

WBOY
Release: 2016-05-16 16:08:23
Original
1159 people have browsed it

The example in this article describes how jQuery implements dynamic loading of content when the page is scrolled. Share it with everyone for your reference. The specific analysis is as follows:

Many websites, such as twitter and JD.com homepage, will dynamically load the page content when the page scrolls to a certain position. This can speed up the opening of the page and save bandwidth. The following JS code can help you do it. arrive.

var loading = false;
$(window).scroll(function(){
 if((($(window).scrollTop()+$(window).height())+250)>=$(document).height()){
  if(loading == false){
   loading = true;
   $('#loadingbar').css("display","block");
   $.get("load.php?start="+$('#loaded_max').val(), function(loaded){
    $('body').append(loaded);
    $('#loaded_max').val(parseInt($('#loaded_max').val())+50);
    $('#loadingbar').css("display","none");
    loading = false;
   });
  }
 }
});
$(document).ready(function() {
 $('#loaded_max').val(50);
});
Copy after login

I hope this article will be helpful to everyone’s jQuery programming.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template