2017-07-21 42 views
0

我的下面的代碼(or jsfiddle)不起作用。不過,它確實適用於我的移動應用程序。它應該做的是使箭頭(滾動到底部按鈕)在底部淡出,然後在返回時淡入視圖中。滾動到底部不發射行爲

爲什麼它不能在瀏覽器(鉻)?

$(window).bind("mousewheel DOMMouseScroll scroll swipe touchmove touchstart", function (e) { 
    var hT = $('#bottom').length ? $('#bottom').offset().top : 0, 
      hH = $('#bottom').outerHeight(), 
      wH = $(window).height(), 
      wS = $(this).scrollTop(); 
    if (wS > (hT + hH - wH)) { 
     $('.saveForm').fadeOut(); 
    } else { 
     $('.saveForm').fadeIn(); 
    } 
}); 

回答

3

你只是缺少符號 「=」;)

$(window).bind("mousewheel DOMMouseScroll scroll swipe touchmove touchstart", function (e) { 
    var hT = $('#bottom').length ? $('#bottom').offset().top : 0, 
      hH = $('#bottom').outerHeight(), 
      wH = $(window).height(), 
      wS = $(this).scrollTop(); 
    if (wS >= (hT + hH - wH)) { // = here when it is at the bottom 
     $('.saveForm').fadeOut(); 
    } else { 
     $('.saveForm').fadeIn(); 
    } 
}); 

請注意,該功能勢必滾動事件。如果您想在點擊箭頭按鈕時隱藏該按鈕,則還需要對該事件進行檢查(onclick)。

+1

Doh!謝謝。有時你需要另一雙眼睛。 –