[英]how to detect user is in bottom using javascript in desktop
我需要的
问题
其附加类在滚动页面的最后。
我需要在上面添加300px类。
jsfiddle: http://jsfiddle.net/8PkQN/1/
我试过了:(window.innerHeight + window.scrollY)== $(document).height()
码
var bottom = $(document).height() - $(window).height(); if($(window).scrollTop() + 1 >= bottom - 2200==true) { $(".abslouel_left12").addClass("fixed_left_btm"); }
工作代码
window.onscroll = function(ev) { if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) { $(".abslouel_left12").addClass("fixed_left_btm"); } }; $(window).scroll(function() { $(this).scrollTop() > 75 && ($(".abslouel_left12").addClass("fixed_left"), $('[data-toggle="tooltip"]').tooltip()), $(this).scrollTop() < 75 && ($(".abslouel_left12").removeClass("fixed_left"), ) if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) { $(".abslouel_left12").removeClass("fixed_left"); }
情况1(当用户位于顶部时)。 没有要添加的类。
这一直对我有用:
if (window.pageYOffset == $(document).height() - $(window).height()) {
// bottom of page
}
如果要知道它们达到页脚上方,则可以将页脚高度添加到计算中。
if ($(window).scrollTop() >= $(document).height() - $(window).height() - $('footer').height()) {
// top of footer
}
小提琴: http : //jsfiddle.net/8PkQN/449/
当您到达页脚顶部时,就会发生警报。 那是您要找的东西吗?
$(window).scroll(function(){
if ($(document).scrollTop() + $(window).height() == $(document).height()) {
//addClass('fixed_length_btm');
} else {
//removeClass('fixed_length_btm');
};
});
$(document).scrollTop()
将为您提供滚动高度。 当文档高度等于滚动高度加窗口高度时,您将在页面底部。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.