Example 1 Download the content when the middle page is reached.
Use the jQuery .scroll() method event to fire the event when the window scrolls.
From there, you can simply use .scrollTop() to get the current browser position associated with the top of the page, and using .height() to get the maximum height of the window and divide by 2 to get the center point.
Once .scrollTop() passes the center point, you find the middle.
$(window).scroll(function() { if ($(window).scrollTop() > $(window).height() / 2) {
Demo Screenshot
Example 2 Upload content when the identity element scrolls (it’s more like the way Facebook works, they have the “Load more” element on the page and when it scrolls into this view, it means that you get to the end of the content and load more.
Another method you can use is to use this function
function isScrolledIntoView(elem) { var docViewTop = $(window).scrollTop(); var docViewBottom = docViewTop + $(window).height(); var elemTop = $(elem).offset().top; var elemBottom = elemTop + $(elem).height(); return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom)); }
In Scott Dowding in this answer Check if an item is visible after scrolling
What can be used to detect when an item is visible inside the browsers viewing area. With this method, you can have an element at the bottom / in the middle of the page and use .scroll() again to fire the event in the scroll.
When this item comes into view, run your code to download more content or whatever you do.
$(window).scroll(function () { if (isScrolledIntoView($('#loadmorecontent'))) { // element has been scrolled into view, load extra contents here alert('element scrolled into view'); // Uncomment out the line below to unbind the scroll event if the // execution of this code is only desired once. // $(this).unbind('scroll'); } }); function isScrolledIntoView(elem) { var docViewTop = $(window).scrollTop(); var docViewBottom = docViewTop + $(window).height(); var elemTop = $(elem).offset().top; var elemBottom = elemTop + $(elem).height(); return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom)); }
Demo Screenshot