jQuery-检测div的底部是否接触到浏览器窗口的底部? [英] jquery - detecting if the bottom of the div is touching the bottom of the browser window?

查看:65
本文介绍了jQuery-检测div的底部是否接触到浏览器窗口的底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在页面上给定一个div.如何检测div何时滚动到浏览器窗口底部的位置...与浏览器窗口底部齐平?

Given a div on a page. how to detect when the div is scrolled to the position where it is at the bottom of the browser window... flush with the bottom of the browser window?

推荐答案

检查

if (($("#yourdiv").offset().top + $("#yourdiv").height()) >= $(window).height()) {
}

.offset()方法允许我们检索元素相对于文档的当前位置.将此与.position()进行对比,后者会相对于偏移父级获取当前位置.

The .offset() method allows us to retrieve the current position of an element relative to the document. Contrast this with .position(), which retrieves the current position relative to the offset parent.

查看 工作演示

这篇关于jQuery-检测div的底部是否接触到浏览器窗口的底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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