2011-10-29 116 views
1

我正在尝试制作无限滚动的网页。现在的问题是,它似乎并没有现在的工作:滚动到页面底部和无限滚动

window.scroll(function() { 
    alert('Scrolling'); 
    if ($(this)[0].scrollHeight - $(this).scrollTop() == $(this).outerHeight()) { 
      alert('Reached the bottom'); 
    } 
    }); 

我真的很新的jQuery的,即使它的基本的JavaScript(?右)反正,我究竟做错了什么?我也试过document.scroll和document.body.scroll

回答

3

试试这个:

if ($(this).scrollTop() == $(document).height() - $(window).height()) { 
      alert('Reached the bottom'); 
    } 

我jsfiddle'd它和它的作品:http://jsfiddle.net/wcKVK/1/

1

你至少有一个错误。尝试:

$(window).scroll(function() { 
    alert('Scrolling'); 
    if ($(this)[0].scrollHeight - $(this).scrollTop() == $(this).outerHeight()) { 
      alert('Reached the bottom'); 
    } 
    }); 
+0

好的,现在它认识到它是滚动的,谢谢。现在需要弄清楚如何解决已达成的问题。我只是意识到我把'这个'。呃。我试过窗户,它什么都没做。 – Jake

1

我觉得这是你想达到什么目的:

$(window).scroll(function() { 
    if ($('body').scrollTop() + $(window).height() == $('body').outerHeight()) { 
    alert('Reached the bottom'); 
    } 
}); 
+0

这告诉你什么时候你到达屏幕的顶端... –

-1
(function ($) { 
    $(window).scroll(function() { 
     if ($(this).scrollTop() == $(document).height() - $(window).height()) { 
      alert('bottom'); 
     } 
    }); 
}(jQuery)); 

是对我有用的东西。

+0

为什么-1这个确实是这个人所要求的......来吧。 –