我如何判断滚动条是否已到达帖子内容的末尾
how would I tell if the scroll bar has reached the end of post's content?
标题几乎不言自明。那么我将如何使用jQuery或javascript来做到这一点呢?我知道要判断滚动条是否已到达窗口的末尾,它将是这样的。
$(window).scroll(function(){
if ($(window).scrollTop() == $(document).height() - $(window).height()){
alert('you have reached the bottom');
}
});
那么我如何判断它是否已到达特定部分然后发出警报呢?谢谢。
当然,这不是一个难以解决的问题,但请查看jQuery Waypoints...一个非常好的插件,可以满足您的要求。
他们网站上的一个简单示例:
$('.entry').waypoint(function() {
alert('You have scrolled to an entry.');
});
优雅且易于阅读,插件非常小,<4kb。
没有插件的一种方法是这样。
例
// calculate where the bottom of the post is positioned
var postBottom = $(".post").offset().top + $(".post").height();
$(window).scroll(function(){
// check if the bottom of the post is smaller than the window height
if (postBottom < $(window).height()){
alert('you have reached the bottom of the post');
}
});
相关文章:
- 如何通过溢出来判断元素被切断了多少像素:隐藏在父级上
- 如何判断何时将dom节点添加到文档中
- 如何判断请求/承诺是否需要超过5秒才能完成,angular js
- Javascript滑块不滑动,如何判断是否存在JS冲突
- 我可以用JavaScript判断访问者是否'的语言环境遵循美国风格或世界其他地区's风格
- 如何判断页面是否处于打印视图中
- 如何判断我是否在Ionic2的移动平台上
- JavaScript 在 JSON 对象中移动如何判断元素是否存在
- 如何判断 JS Windows8 地铁应用程序是否可见
- 在node.js/ssocket.io中,如何判断对象是否是套接字的实例
- 有没有一种方法可以判断图像src是否在javascript内部返回null
- 如何判断页面是否是从fetch()调用的
- 如何判断是否由于流已被删除而激发了pc.onnegotiationneed
- 如何判断被调用的函数是否源自javascript中的点击事件
- 我如何判断一个符号是否被用作密钥
- 如何使用.find()判断某个元素是否有子元素
- 如何判断字符串中字母的索引?(在Python、JS、Ruby、PHP等中)
- 如何使用readyState判断XHR已发送到服务器
- 如何判断文本输入字段dom节点是否*没有*带有javascript的选择
- 如何判断Meteor minimongo何时与mongo服务器同步