Get the actual height of a document using jQuery

I have a problem with my jQuery plugin, I want to show the footer in a certain way right before the end of the page. To do this, I get the actual lower position and compare it with the height of the whole body.

But there is a jQuery function height () problem return bad value. For example, I know that the site has a height of 5515px, but the function returns me a value: 8142px

I am using the mCustomScrollbar plugin in several places on the page and I think this may cause a problem. I cannot turn it off because there are elements on the page that require good results.

My code is:

(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);

: $(document).height() document.body.clientHeight . $('body'). Height() .

+4
1

,

:

$(window).resize(() {             height = $(document).height();         });

0

All Articles