2014-10-20 19 views
-1

我想實現的目標是在向上或向下滾動時刪除特定的類或隱藏類(以避免滯後)。 我有以下代碼:向上或向下滾動時刪除類

var $div = $('#div'); 
$div.on('mouseenter', '.box', function() { 
    $(this).find('span.category').addClass('bg-category'); 
    $(this).find('.post-options').show(); 
}); 

和//休假:

$div.on('mouseleave', '.box', function() { 
    $(this).find('span.category').removeClass('bg-category'); 
    $(this).find('.post-options').hide(); 
}); 

基本上,我有大量的圖片和滾動,而當鼠標懸停在.box的滯後它的頁面顯著。所以我想要實現的是不僅在'mouseleave'中刪除這些類,而且還可以在頁面上下滾動時刪除這些類。

與google +相似,在滾動鼠標懸停的內容卡片時,鏈接會亮起,但一旦滾動,它們將被刪除。例如:https://plus.google.com/communities/100354381402619402956

回答

0

你可以試試這個:

var lastScrollTop = 0; 
$(window).scroll(function(event){ 
    var st = $(this).scrollTop(); 
    if (st > lastScrollTop){ 
    // downscroll code 
     $("#div").find('.post-options').show(); 
     $(".box").delay(800).addClass('dummyclass'); 
    } else { 
    // upscroll code 
     $("#div").find('.post-options').hide(); 
     $(".box").delay(800).addClass('dummyclass'); 
    } 
lastScrollTop = st; 
}); 
+0

感謝您的回覆,是實際工作,但我忘了提,如果用戶停止滾動我想加入的班級,而無需重新如果你知道我的意思,請將其懸停在.box上。 – Emanradin 2014-10-20 06:05:05

+0

@Emanradin:用戶停止滾動時需要添加的類的名稱是什麼?你想在哪裏添加? – Jinandra 2014-10-20 07:11:50

+0

該類被稱爲'bg-category',它將位於'.box'> span.category> bg-category下。我不太確定'mouseover'會起作用嗎? – Emanradin 2014-10-20 07:43:55

相關問題