检查靠近/在页面的底部 [英] Checking is near/at the bottom of the page

查看:74
本文介绍了检查靠近/在页面的底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检查一个元素是否是来自页面底部的x个像素,以动态加载新的内容。目前,即使栏位于底部,scrollTop和height也不匹配。



允许使用jquery,但基本的javascript会更有帮助。

解决方案

您可能想尝试以下操作(仅在Firefox 3.5和IE 8中测试过):

  function pollScrollPosition(){
var y =(document.all)? document.body.scrollTop:window.pageYOffset;
var max = window.scrollMaxY ||
(document.body.scrollHeight - document.body.clientHeight); ((max - y)< 100){
console.log('在底部100像素内,做些什么!');


}
}

//每250ms检查滚动位置
setInterval(pollScrollPosition,250);

以上Firebug示例中的屏幕截图:

检查靠近页面底部http://img10.imageshack。 us / img10 / 7767 / scrolltop.jpg


I need to check if an element is x pixels from the bottom of the page, to dynamically load new content. currently, scrollTop and height do not match even if the bar is on the bottom.

jquery is allowed, although basic javascript would be more helpful.

解决方案

You may want to try the following (tested in Firefox 3.5 and IE 8 only):

function pollScrollPosition() {
   var y = (document.all) ? document.body.scrollTop : window.pageYOffset;
   var max = window.scrollMaxY || 
             (document.body.scrollHeight - document.body.clientHeight);

   if ((max - y) < 100) {
      console.log('Within the bottom 100 pixels. Do Something!');
   }
}

// Check the scroll position every 250ms
setInterval(pollScrollPosition, 250);

Screenshot from the above example in Firebug:

Checking is near/at the bottom of the page http://img10.imageshack.us/img10/7767/scrolltop.jpg

这篇关于检查靠近/在页面的底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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