计算网页上的滚动结束 [英] Calculating end of scroll on a web page
问题描述
我需要计算网页上的滚动结束,以便我可以进行Ajax调用。
我已经在stackoverflow中搜索帖子,但是这些解决方案并没有为我工作。
我使用下面的代码离子顺序来确定: p>
$(window).scrollTop()== $(document).height() - $(window).height()
但上述情况失败,无法知道页面滚动结束的时间。
由于LHS和RHS上的值不匹配,因此条件失败。
只是为了检查我用过的:
$ $ $ $(window).scrollTop()== $(document) .height() - $(window).height() - 13
适用于Chrome和Firefox但IE失败。
我需要一个具体的解决方案,不想硬编码值。
请帮助我解决问题。
编辑:具体来说,我正在计算垂直滚动条的结尾。 b $ b
这是我会做的:
$(window).on('scroll',function(){
if($(window).scrollTop()!= 0)
{
if($(window))。 ()+ $(window).scrollTop()> = $(document).height())
{
//是的,我正好在SCROLL的末尾,PLZ FIRE AJAX NOW
}
}
});
小心:请务必小心,您网页上的任何元素!它可能会抵消计算!
I need to calculate the end of scrolling on web page so that i can make an Ajax call. I have searched posts in stackoverflow, but the solutions didn't worked for me.
I am using the below code ion order to determine that:
$(window).scrollTop() == $(document).height() - $(window).height()
but the above condition fails and am not able to get to know when page scroll ends.
As the values don't match on L.H.S and R.H.S the condition fails. Just in order to check i used:
$(window).scrollTop() == $(document).height() - $(window).height() - 13
which works for chrome and firefox but fails for IE. I need a concrete solution and don't want to hard code values. Please help me in getting it right.
EDIT: To be specific, i am trying to calculate the end of vertical scroll bar.
Here is what I would do:
$(window).on('scroll', function() {
if($(window).scrollTop() != 0)
{
if( $(window).height() + $(window).scrollTop() >= $(document).height() )
{
//YES, I AM EXACTLY AT THE END OF THE SCROLL, PLZ FIRE AJAX NOW
}
}
});
CAUTION: Be very careful about having negative top margins though for styles in any of your elements on the page!! it may offset the calculation!
这篇关于计算网页上的滚动结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!