jQuery Mobile用户滚动到底部 [英] JQuery Mobile User scroll to bottom
问题描述
使用以下代码,我试图查找用户何时滚动到页面底部.在JQuery移动版中.
With the following code, I am trying to find when the user scrolls to the bottom of the page. In JQuery mobile.
$(window).scroll(function(){
if($(window).scrollTop() == $(document).height() - $(window).height()){
alert("The Bottom");
}
});
现在我只希望它输出他们已经到达最低点了.
For now I am just wanting it to output that they have reached the bottom.
我的问题是,当网站加载时,它将输出此消息.当我滚动到底部时,它将输出警报.
My problem is, when the site loads, it will output this message. When I scroll to the bottom it will then output the alert.
有没有一种方法可以在页面加载后停止它,而仅在用户实际滚动页面时才停止呢?
Is there a way to stop it doing it for when the page has loaded and only do it when the user has physically scrolled the page?
谢谢
推荐答案
是因为您的内容比您的页面短吗?这意味着在加载时,您已经处于最底端.我已经尝试在 http://jsfiddle.net/qESXR/2/中复制您的问题,并且它的行为就像您想要的那样.但是,如果我缩短内容并在计算机上本地运行,则会得到与您相同的结果.
如果是这样,您可以使用这些检查页面的高度与html的高度
Is it because your content is shorter than your page? Meaning that when it loads, you are already at the bottom. I have tried to replicate your problem here http://jsfiddle.net/qESXR/2/ and it behaves like you want. However if I shorten the content and run it locally on my machine I get the same result you have.
If so, you might check for the height of the page vs height of your html using these
$(window).height(); // returns height of browser viewport
$(document).height(); // returns height of HTML document
像这样:
$(window).scroll(function(){
if($(document).height() > $(window).height())
{
if($(window).scrollTop() == $(document).height() - $(window).height()){
alert("The Bottom");
}
}
});
这篇关于jQuery Mobile用户滚动到底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!