jquery - JavaScript to detect bottom of page does the reverse on Chrome -
i'm trying infinite scrolling page, condition test if we're @ bottom of page not behaving correctly on chrome. on chrome alert seems trigger @ top of page rather when hitting bottom. works correctly on ie11 though.
on chrome $(document).height() equals 0. have <!doctype html>
html @ top of page if matters.
oddly took example worked within jsfiddle on chrome: http://jsfiddle.net/nick_craver/gwd66/
$(window).scroll(function () { if ($(window).scrolltop() + $(window).height() == $(document).height()) { alert("test"); } } }
what kind of css applied page, more body element? padding or margin making $(document).height() equal more combination of $(window).scrolltop() , $(window).height(). following code determine if ever meeting if() criteria.
what version of jquery using?
$(window).scroll(function() { var scrollposition = $(window).scrolltop() + $(window).height(); var bodyheight = $(document).height(); $("#scrollindex").html( scrollposition + " / " + bodyheight ); if( scrollposition == bodyheight ) { $("#scrollindex").html( "bottom!" ); $('body').height( bodyheight + 200 + "px" ); } });
body{ height:2000px; } #scrollindex{ position:fixed; top:0px; right:0px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div id='scrollindex'></div>
Comments
Post a Comment