javascript - Get actual height of document with jQuery -
i have problem jquery plugin, want display footer in specific way right before end of page. actual bottom position , compare height of entire body.
but there problem jquery function height() return bad value. example know site has height of 5515px function returns me value: 8142px
i use plugin mcustomscrollbar in few places on page, , think may cause problem. can't disable it, because page has elements require good.
my code:
(function($){ $.fn.scrollingelements = function(){ var height = $(window).height(); var max_height = $(document).height(); var prev_top = $(window).scrolltop(); var prev_bottom = top + height; $(window).scroll(function(){ var top = $(window).scrolltop(); var bottom = top + height; console.log(max_height, bottom); if(prev_top < height && top > height){ // console.log('show header', 'show sticky', 'show footer small'); } if(prev_top > height && top < height){ // console.log('hide header', 'hide sticky', 'hide footer'); } if(prev_top < 2*height && top > 2*height){ // console.log('show sroll top'); } if(prev_top > 2*height && top < 2*height){ // console.log('hide scroll top'); } if(prev_bottom < max_height - 100 && bottom > max_height - 100){ // console.log('show footer large'); } if(prev_bottom > max_height - 100 && bottom < max_height - 100){ // console.log('show footer small'); } prev_top = top; prev_bottom = bottom; }); $(window).resize(function(){ height = $(window).height(); }); } })(jquery);
answering tommy riordan: changing $(document).height() document.body.clientheight didn't work still getting bad results. tried using $('body').height() same effect.
please use
document
instead of window example :
$(window).resize(function(){ height = $(document).height(); });
Comments
Post a Comment