Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Example 1</strong> - Load content when middle of page reached</p> <p>Make use of the jQuery <code>.scroll()</code> method event to fire an event when the window is scrolled.</p> <p>From there you can simply use <code>.scrollTop()</code> to get the current position in the browser related to the top of the page, along with using <code>.height()</code> to get the max height of the window and dividing by 2 to get the center point.</p> <p>Once <code>.scrollTop()</code> is pass the center point you have found the middle.</p> <pre><code>$(window).scroll(function() { if ($(window).scrollTop() &gt; $(window).height() / 2) { // middle of page hit, load extra content here alert('You are in the middle of the page'); // Uncomment out the line below to unbind the scroll event if the // execution of this code is only desired once. // $(this).unbind('scroll'); } }); </code></pre> <p><a href="http://jsfiddle.net/HszaK/" rel="nofollow noreferrer">Fiddle Demo</a></p> <hr> <p><strong>Example 2</strong> - Load content when an identifying element scrolls into view (this is more similar to how Facebook works, they have a "Load More" element on there page and when its scrolled into view that means you reach the end of the content and to load more.</p> <p>Another method you can use is to make use of this function</p> <pre><code>function isScrolledIntoView(elem) { var docViewTop = $(window).scrollTop(); var docViewBottom = docViewTop + $(window).height(); var elemTop = $(elem).offset().top; var elemBottom = elemTop + $(elem).height(); return ((elemBottom &gt;= docViewTop) &amp;&amp; (elemTop &lt;= docViewBottom)); } </code></pre> <p>By <a href="https://stackoverflow.com/users/41669/scott-dowding">Scott Dowding</a> in this answer <a href="https://stackoverflow.com/questions/487073/jquery-check-if-element-is-visible-after-scroling">Check if element is visible after scrolling</a> </p> <p>Which can be used to detect when an element is visible inside the browsers viewing area. With such a method you can have an element at the bottom/middle of your page and again make use of <code>.scroll()</code> to fire an event on scroll.</p> <p>When that element comes into view, fire your code to load more content or whatever you want to do.</p> <pre><code>$(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 &gt;= docViewTop) &amp;&amp; (elemTop &lt;= docViewBottom)); } </code></pre> <p><a href="http://jsfiddle.net/ey4cW/" rel="nofollow noreferrer">Fiddle Demo</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload