2015-08-17 103 views
4

我試圖讓我自己的版本的wow.js,因爲兩個原因,第一個是它似乎不再維護wow.js,第二個因爲它只顯示動畫一旦動畫不會顯示隱藏塊

我已經是我的代碼並不顯示動畫向下滾動時,只有向上滾動時,我發現CAND爲什麼這個問題...

誰能幫我找到這個錯誤嗎?

負責顯示元素的功能是這樣的:

function showBlocks() { 
    $('.wow2').each(function() { 
     var elementTop = $(this).data('wow2-top'); 

     $(this).html(elementTop); 

     // Shows Elements 
     if ((elementTop >= top) && (elementTop <= bottom)) { 
      $(this).css('visibility', 'visible'); 
      $(this).addClass('animated').addClass($(this).data('wow2-class')); 
     } 
     /* 
     // Hides Elements 
     if ((elementTop < top) || (elementTop >= bottom)) { 
     $(this).css('visibility', 'hidden'); 
     $(this).removeClass('animated').removeClass($(this).data('wow2-class')); 
     } 
     */ 
    }); 

} 

這裏是我的jsfiddle

回答

2

在滾動您要更新爲top的價值而不是bottom。嘗試

$(window).scroll(function() { 
    top = $(window).scrollTop(); 
    bottom = top + viewportHeight; 
    showBlocks(); 
    writePosition(); 
}); 

https://jsfiddle.net/5q7gryqr/4/

+0

該死!爲什麼很難找到一個明顯的錯誤?感謝您的幫助......它完美運作 – Chico3001