Page rollback effect (scroll bar to bottom refresh page)

Source: Internet
Author: User

jquery scrolling monitoring method is as follows, $ (window). Scroll (function () {var scrolltop = $ (this). ScrollTop ();    var scrollheight = $ (document). Height ();    var WindowHeight = $ (this). Height ();    if (scrolltop + windowheight = = scrollheight) {alert ("You were in the bottom"); }  }); In the actual application, such as Weibo, QQ space, such as this effect, open the home page by default display a few, but our mouse will slide the scroll bar to the bottom, loading more content, how is this method implemented? Customs clearance of the Demo,simple-weibo has such a requirement, the personal use of Ajax and jquery scroll method together to achieve this effect, the idea is as follows: 1, set the ScrollBar listener event, as shown above 2, when ScrollTop + windowheight = = scrollheight, alert replaces the Ajax method, returning the data to be spit out from the backend, as follows

$.ajax ({
Type: ' POST ',
URL: "pub.php",

Data:id,///For example, the home page default display 10, from the Param to get parameters, such as set to 1, 2, 3 means scrolling to the bottom, SQL Skip 10 fetch n.

Success:function (data) {
$ ("#moreinfo"). before (data);

History.go (0); So that the data in the database is displayed
},
Fail:function () {
Alert (' request failed! ‘);
}
});

Because the data is not needed, the Ajax method does not mention that data in Data,success is returned from the pub.php.

Encountered a problem in the process, because each time to the bottom, only loaded a message, because the use of Ajax, where the DOM is false data, not really exist with the HTML, only refreshed, the display is the data extracted from the database. In addition, because the list is displayed by default, in order for each loaded data to be displayed from the bottom, we can build a <div id= "moreinfo" ></div> but not write anything, just to provide support for the before method of data spit. Specific reasons can be understood!

Page rollback effect (scroll bar to bottom refresh page)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.