我正在網上產品的網站,我trigging滾動事件,在開始只有12個元素將被顯示,但在第八元素滾動到頂部滾動事件應該只運行一次,但當我向下滾動時,它正在運行,請幫助。 這裏是我的代碼:只有一個條件後,一旦運行jQuery的事件匹配
var navigation_offset_top = $('.prods-list li:nth-child(4)').offset().top;
$(window).on("scroll",function(){
var scroll_top = $(window).scrollTop(); // current vertical position from the top
// if scrolled more than the navigation, change its position to fixed to stick to top, otherwise change it back to relative
if (scroll_top > sticky_navigation_offset_top)
{
console.log("Hi");
}
});
只需刪除事件處理程序。 – 2013-03-26 12:37:29
在啓動時放置了一個var trigger = true。 後先點擊使假, 基於它允許滾動或不 – Bhadra 2013-03-26 12:37:43