what is difference between $('body').height() ,$('window').height() , $('document').height()

Viewed 34

I am looking at the code written by someone else. In this a class is added of removed when we reach a particular section.I cannot understand the use of $('body').height() here

if($('#impact_calculator'). length){
        $(window).scroll(function () {
        var scroll = $(window).scrollTop();
        // var box = $('#impact_calculator').offset().top -190;
        var box = $('body').height() - $('#impact_calculator').height() - 450;
        if (scroll >= box) {
            setTimeout(() => {
            $("body").addClass("sticky");
            }, 500);
        } else {
            setTimeout(() => {
                $("body").removeClass("sticky");
            }, 500);
        }

    });
1 Answers

kindly refer to this link for your reference : https://api.jquery.com/height/

// Returns height of browser viewport
$( window ).height();

Usually $ (window). height() delivers the browser window's height less one pixel. The height of the current browser window is always this. This value do need to alter as your browser is resized.

// Returns height of HTML document
$( document ).height();

$(document).height() function: $(document). height() returns an unit-less pixel value of the height of the document being rendered.

Related