2014-09-26 12 views
1

我不知道它是否容易或不,但我只是無法找出Waypoint.js 我需要添加一個類#stickytop用戶到達時,爲前100px的滾動 任何想法如何做到這一點? 抵消不適合我。 在此先感謝Waypoint.js:添加班級時,N距離頂部

回答

0

這不是jQuery waypoints的用例。它旨在測試特定元素離屏幕頂端的距離,而不是用戶滾動的距離。

但是您可以輕鬆地你想要做什麼用jQuery:

$(document).on('scroll', function() { 
    // if the scroll distance is greater than 100px 
    if ($(window).scrollTop() > 100) { 
     // do something 
     $('#stickytop').addClass('myClass'); 
    } 
}); 

或香草的JavaScript:

document.addEventListener('scroll', function() { 
    if (window.scrollY > 100) { 
    var el = document.getElementById('#stickytop'); 
    el.className = el.className + " myClass"; 
    } 
}) 
+0

,這是很容易的。非常感謝 – canute 2014-09-26 15:57:34

+0

@掃描沒問題:) – Jivings 2014-09-26 15:59:04