What is the difference between $(document).height() and $(window).height()

前端 未结 5 1008
不思量自难忘°
不思量自难忘° 2021-02-13 23:25

(Hope it is not a duplicate because I didn\'t find it when searching and googling)

I am trying to find how to detect in some fixed-height div (\'#div\') when the scroll-

5条回答
  •  滥情空心
    2021-02-13 23:43

    Difference between $(window).height() and $(document).height() function.

    $(window).height() function:

    Ideally $(window).height() returns the pixel less height of browser window. This is always the height of current browser window. If you resize browser this value should change.

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

    In HTML if you dont declare DOCTYPE then all time HTML page returns $(window).height() and $(document).height() same value.

    
        
            
    
    
            
        
        
            
    $(window).height() =
    $(document).height() =

    Lorem ipsum dolor sit amet

    Output :

    $(window).height() = 750 
    $(document).height() = 750
    Lorem ipsum dolor sit amet
    

    After declare DOCTYPE its returns perfect value.

    
    
        write above code here
    
    

    Output :

    $(window).height() = 750 
    $(document).height() = 750
    Lorem ipsum dolor sit amet
    

提交回复
热议问题