jquery - Alter code to when scrolled to the bottom -


trying adjust code work when user reaches bottom of content opposed top. works fine, top.

<script>  $(function(){  var shrinkheader = 150;  $(window).scroll(function() {  var scroll = getcurrentscroll();   if ( scroll >= shrinkheader ) {        $('.button').addclass('shrink');        $('.brand').addclass('shrink');     }     else {         $('.button').removeclass('shrink');         $('.brand').removeclass('shrink');     }   });  function getcurrentscroll() {   return window.pageyoffset || document.documentelement.scrolltop; } }); </script> 

i want function does, when user reaches 150px bottom, not top

use:

$(document).scrolltop(); 

to get/detect distance scrolled top in jquery.

if want get distance bottom.

i suggest using:

// returns height of browser viewport $( window ).height();  // returns height of html document $( document ).height(); 

getting distance:

distance = parseint($(document).height()) - parseint(getcurrentscroll()); 

test code here

your $(window).scroll(function(){...}); correct!

you need update function getcurrentscroll()

//use: return $(document).scrolltop();  //instead of:     return window.pageyoffset || document.documentelement.scrolltop; 

then choose either $(window).height() or $(document).height():

 distance = parseint($(document).height()) - parseint(getcurrentscroll());       if ( distance >= shrinkheader ) {     // adding or removing of class ....  } 

do adjustments of checking distance based on result want get.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -