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()); 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
Post a Comment