admin管理员组文章数量:1398766
I need to detect if user scrolled to the bottom of the page so I can make some action.
But I did something wrong and when I scroll to the bottom nothing happens but when I scroll to the top it fires the action :(.
And should opposite :)
$(window).scroll(function () {
if ($(window).scrollTop() == $(document).height() - $(window).height() && !($('#imgLoad').is(':visible'))) {
alert('you hit bottom');
loadMore();
}
});
I need to detect if user scrolled to the bottom of the page so I can make some action.
But I did something wrong and when I scroll to the bottom nothing happens but when I scroll to the top it fires the action :(.
And should opposite :)
$(window).scroll(function () {
if ($(window).scrollTop() == $(document).height() - $(window).height() && !($('#imgLoad').is(':visible'))) {
alert('you hit bottom');
loadMore();
}
});
Share
Improve this question
edited Jan 4, 2021 at 21:16
Brian Tompsett - 汤莱恩
5,89372 gold badges61 silver badges133 bronze badges
asked Sep 8, 2013 at 14:15
11101110
6,85956 gold badges187 silver badges346 bronze badges
6 Answers
Reset to default 4please try this one
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
alert("bottom!");
}
});
you can also have another option on the following question: Check if a user has scrolled to the bottom
This is an old post, but posting in case this helps someone else in the future. I was experiencing the same problem. The event would fire as I scrolled to the top of the page from the bottom. Using document.body.clientHeight instead of $(window).height fixed things for me. This was tested using Chrome.
$(window).scroll(function() {
if($(window).scrollTop() + document.body.clientHeight == $(document).height()) {
alert('bottom of page');
}
});
if (document.body.offsetHeight + document.body.scrollTop>= document.body.scrollHeight){
alert("bottom!");
}
$(window).on("scroll", function() {
var scrollHeight = $(document).height();
var scrollPosition = $(window).height() + $(window).scrollTop();
if ((scrollHeight - scrollPosition) / scrollHeight === 0) {
// when scroll to bottom of the page
}
});
if($(window).scrollTop() + $(window).height() > $(document).height()-200) {
alert();
// add your custom function here. i.e what you want to do.
}
This will work.The user scrolls down the page and when the if(condition) is met the code is executed.
Please try this.
following scroll function would be worked while window scrolling bottom in asp
$(window).scroll(function() {
$(window).scrollTop() + document.body.clientHeight == $(document).height()
});
and following scroll function would be worked while window scrolling bottom in html or mvc page view.
$(window).scroll(function() {
$(window).scrollTop() == $(document).height() - $(window).height()
});
本文标签: javascriptCheck if user scroll to bottom of the page work oppositeStack Overflow
版权声明:本文标题:javascript - Check if user scroll to bottom of the page work opposite - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744120967a2591737.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论