$(document).height()和$(window).height()有什么区别 [英] What is the difference between $(document).height() and $(window).height()

查看:103
本文介绍了$(document).height()和$(window).height()有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(希望它不是重复的,因为我在搜索和谷歌搜索时没有找到它)

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

我试图找到当滚动条到达后一个div底部时如何在固定高度div('#div')中进行检测的方法.我应该使用$(document).height()$(window).height()来检测此事件吗?

I am trying to find how to detect in some fixed-height div ('#div') when the scroll-bar is reaching the bottom of this latter div. Should I use $(document).height() and $(window).height() to detect this event ?

我的div是固定高度的,关于它我设置了自动滚动,那么如何处理呢?如果我假设使用$('#div').height(),则此高度是固定的....

Edit : My div which is fixed-height and about which I set auto-scroll, so how to deal with that ? if I am suppose to use $('#div').height(), this height is fixed....

推荐答案

.height() 文档中:

$(window).height();   // returns height of browser viewport
$(document).height(); // returns height of HTML document

在您的情况下,听起来您可能想要document而不是window的高度.可以这样考虑:window高度是您所看到的,但是document高度包括以下或以上的所有内容.

In your case it sounds like you may want the height of the document rather than the window. Think of it this way: The window height is what you see, but the document height includes everything below or above.

示例

EXAMPLE

编辑:

scrollTop() 方法的帮助下,检查滚动顶部和底部:

Checking for top and bottom on scroll with help from the scrollTop() method:

var bottom = $(document).height() - $(window).height();

$(document).scroll(function(){
    var position = $(this).scrollTop();
    if (position === bottom) {
        console.log("bottom");
    }else if(position === 0){
        console.log("top");   
    } else {
        console.log("scrolling");
    }
});

这篇关于$(document).height()和$(window).height()有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆