[英]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.