Jquery Method for Rolling Data Loading
This article mainly introduces jquery's method of rolling data loading. The example analyzes jQuery's techniques of dynamically loading data, which has some reference value. For more information, see
This document describes how to use jquery to load data by scrolling. Share it with you for your reference. The specific analysis is as follows:
When we browse some web pages, when the browser's scroll bar is pulled to the bottom of the page, the page will continue to automatically load more content for users to browse. For the moment, this technology is called the scrolling loading technology. We found that many websites use this technology, such as Sina Weibo and QQ space.
The Code is as follows:
The Code is as follows:
<! DOCTYPE = html>
<Html>
<Head>
<Script src = "js/jquery. js" type = "text/javascript"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
Var range = 50; // the length from the bottom boundary/unit: px
Var elmep = 500; // insert element height/unit px
Var maxnum = 20; // you can specify the maximum number of loads.
Var num = 1;
Var totalheight = 0;
Var main = $ ("# content"); // subject Element
$ (Window). scroll (function (){
Var srollPos = $ (window). scrollTop (); // The distance from the scroll bar to the top (the page exceeds the window height)
// Console. log ("vertical height from the scroll bar to the top:" + $ (document). scrollTop ());
// Console. log ("document height on the page:" + $ (document). height ());
// Console. log ('browser height: '+ $ (window). height ());
Totalheight = parseFloat ($ (window). height () + parseFloat (srollPos );
If ($ (document). height ()-range) <= totalheight & num! = Maxnum ){
Main. append ("<div style = 'border: 1px solid tomato; margin-top: 20px; color: # ac" + (num % 20) + (num % 20) + "; height: "+ elemt +" '> hello world "+ srollPos +" --- "+ num +" </div> ");
Num ++;
}
});
});
</Script>
</Head>
<Body>
<Div id = "content" style = "height: 960px">
<Div id = "follow"> this is a scroll test; <br/> automatically loads content from the drop-down menu </div>
<Div style = 'border: 1px solid tomato; margin-top: 20px; color: # ac1; height: 800 '> hello world test DIV </div>
</Div>
</Body>
</Html>
I hope this article will help you with jQuery programming.