gpt4 book ai didi

JQuery Mobile 用户滚动到底部

转载 作者:行者123 更新时间:2023-12-03 22:39:45 25 4
gpt4 key购买 nike

使用以下代码,我试图找到用户何时滚动到页面底部。在 JQuery 移动版中。

$(window).scroll(function(){
if($(window).scrollTop() == $(document).height() - $(window).height()){
alert("The Bottom");
}
});

现在我只想输出它们已经到达底部。

我的问题是,当网站加载时,它会输出此消息。当我滚动到底部时,它将输出警报。

有没有办法在页面加载时阻止它执行此操作,并且仅在用户物理滚动页面时才执行此操作?

谢谢

最佳答案

是因为您的内容比您的页面短吗?这意味着当它加载时,你已经在底部了。我试图在这里复制您的问题http://jsfiddle.net/qESXR/2/它的行为就像你想要的那样。但是,如果我缩短内容并在我的计算机上本地运行它,我会得到与您相同的结果。
如果是这样,您可以使用这些检查页面的高度与 html 的高度

$(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 用户滚动到底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9296914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com