1

http://codepen.io/BrianDGLS/pen/yNBrgR

This is what I am currently using which allows the user to track where he is on the page.

What would I have to do to show a div when the user reaches the bottom of the page? And continue to show it until he hits refresh

#show {display: none}

<div id="show">
<p>Hello</p>
<p>World!</p>
</div>

Show the div '#show' when the user reaches the bottom of the page and continue to show it for as long as he stays on the page.

  • Take a look here http://stackoverflow.com/questions/10059888/detect-when-scroll-reaches-the-bottom-of-the-page-without-jquery – Henrique Arthur Apr 21 '15 at 17:35
  • scrolled to bottom: http://stackoverflow.com/questions/3898130/how-to-check-if-a-user-has-scrolled-to-the-bottom im curious if you can persist the div with only client side (you can do it with cookies I'm guessing) – Symba Apr 21 '15 at 17:43

4 Answers4

2

Using a convention that mirrors the sample JS code:

        $(window).scroll(function() {
          var wintop = $(window).scrollTop(),
            docheight = $(document).height(),
            winheight = $(window).height(),
            scrolled = (wintop / (docheight - winheight)) * 100;

          if (scrolled >= 100) {
            $(yourDiv).show();
          }
        });

The computation of the scroll percentage is straight from the link you provided and the condition just checks if you've reached 100% of the page (minus current window size).

You could also change 100 to be whatever percentage if you want to load the div before the user reaches the absolute bottom.

arcyqwerty
  • 10,325
  • 4
  • 47
  • 84
1

It could be something like:

$(window).on('scroll', function(){
    var op = $(window).scrollTop() + $(window).height();
    if( op >= $(document).height() ) $("#show").show();
});
kosmos
  • 4,253
  • 1
  • 18
  • 36
0

You need to trigger a Javascript function when the <div id="show"> is visible in the client's viewport, for that you can use a plugin

odedta
  • 2,430
  • 4
  • 24
  • 51
0

try below code

var show=false;
$(window).scroll(function() {
   if($(window).scrollTop() + $(window).height() == $(document).height() || show==false) {
       $("#show").show();
       show=true;
   }
});
nirmal
  • 2,143
  • 1
  • 19
  • 29