簡體   English   中英

如何使用桌面中的javascript檢測用戶是否在底部

[英]how to detect user is in bottom using javascript in desktop

我需要的

  • 當用戶向下滾動頁面時,我需要使用js添加類。

問題

  • 其附加類在滾動頁面的最后。

  • 我需要在上面添加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(當用戶位於頂部時)。 沒有要添加的類。

  • 情況2,當用戶向下滾動添加類(.fixed_length)時。
  • 情況3,當用戶滾動到底部時,添加class(.fixed_length_btm),但問題是情況3代碼在滾動瀏覽器的工作結束時,我需要將其置於頁面頁腳上方。

這一直對我有用:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM