Key code:
var stop=true;
$(window) .scroll(function(){
totalheight = parseFloat($(window).height()) parseFloat($(window).scrollTop());
if($(document).height() < = totalheight){
if(stop==true){
stop=false;
$.post("ajax.php", {start:1, n:50},function(txt){
.
HTML:
Copy code
The implementation method is to compare the total height of the page and the scroll height to determine whether it has reached the bottom. If it reaches the bottom, read more content through ajax, and use before to insert it before Loading.
The stop parameter takes into account the time consuming of ajax reading and prevents events from being triggered multiple times during an ajax reading process, resulting in multiple loading of content.