$(window).height() vs $(document).height

前端 未结 5 773
小鲜肉
小鲜肉 2020-12-02 08:56

I am having problem of getting wrong height with

$(window).height();

and got the similar question here

In my case when I try

5条回答
  •  青春惊慌失措
    2020-12-02 09:08

    Well you seem to have mistaken them both for what they do.

    $(window).height() gets you an unit-less pixel value of the height of the (browser) window aka viewport. With respect to the web browsers the viewport here is visible portion of the canvas(which often is smaller than the document being rendered).

    $(document).height() returns an unit-less pixel value of the height of the document being rendered. However, if the actual document’s body height is less than the viewport height then it will return the viewport height instead.

    Hope that clears things a little.

提交回复
热议问题