2015-01-06 17 views
-2

我想刪除一個類focus-mode當用戶滾動頁面或者用鼠標滾輪或滾動條:什麼是滾動頁面的jQuery事件?

$("#input-content").on("SCROLLING_EVENT", function(e) { 
    $(".chapter-form").toggleClass("focus-mode"); 
}); 

但我無法找到,網上什麼。 jQuery是否有滾動事件?如果不是,那麼我最想達到的目標是什麼?

+0

'$(「#input-content」).roll(function(){....});'see here:http://api.jquery.com/scroll/ – Riad

+0

http:// api.jquery.com/scroll/還要注意,這個事件觸發了*每一個像素*滾動,所以你的'focus-mode'類將在每個滾動上切換成數千次。 –

回答

1

這是普通的舊"scroll"

.on("scroll", handler) 

引述.scroll() documentation

此方法是在第一 和第二變化。對用於快捷方式( 「滾動」,處理程序),和.trigger( 「滾動」)在第三。

0
$(window).scroll(function(){ 
    $(".chapter-form").toggleClass("focus-mode"); 
}); 

此代碼會在您每次滾動時觸發。

1

使用scroll event一樣,

$(function(){ 
    $('#input-content').scroll(function(e) { 
     $(".chapter-form").toggleClass("focus-mode"); 
    }); 
});