2012-04-13 18 views
3

可能重複:
Can I declare logic on jQuery for the start and end of a scrolling event?只有當我開始滾動時纔可能調用函數嗎?

嘗試這樣:

$(window).scroll(function() { 
    console.log("ciao"); 
}); 

但功能滾動過程中調用。我只想在開始滾動時打印「ciao」。不是。那麼,阻止滾動後,當我重新啓動,再次打印「ciao」,等等。

僅當我開始滾動時纔可能調用函數嗎?

+0

http://stackoverflow.com/questions/4096429/can-i-declare-logic-on-jquery-for-the-start-and末端 - - 一個滾動事件的 – Dev 2012-04-13 09:21:40

回答

2

沒有內置的jQuery功能,它允許你檢測滾動開始或停止事件。

雖然有幾個插件可以啓用此功能,但請嘗試this one

然後,您可以更改您的代碼如下:

$(window).on('scrollstart', function() { 
    console.log("ciao"); 
}); 
2
$(window).bind("scrollstart", function() { 
console.log("ciao"); 
}); 

您必須首先包含jquery.scroll.events.js文件。你可以尋找更多的herehere

相關問題