Jquery $(window).height() function does not return actual window height

前端 未结 7 2104
渐次进展
渐次进展 2020-12-09 16:09

I have a page that I need to dynamically load ajax content when the user scrolls to the bottom. The problem is that JQuery is not returning the correct window height. I have

7条回答
  •  旧巷少年郎
    2020-12-09 16:21

    //works in chrome
    $(window).bind('scroll', function(ev){
    
        //get the viewport height. i.e. this is the viewable browser window height
        var clientHeight = document.body.clientHeight,
            //height of the window/document. $(window).height() and $(document).height() also return this value.
            windowHeight = $(this).outerHeight(),
            //current top position of the window scroll. Seems this *only* works when bound inside of a scoll event.
            scrollY = $(this).scrollTop();
    
        if( windowHeight - clientHeight === scrollY ){
            console.log('bottom');
        }
    
    });
    

提交回复
热议问题