Last active
December 10, 2015 22:39
-
-
Save atleastimtrying/4504130 to your computer and use it in GitHub Desktop.
a basic scroll position detector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ScrollTracker | |
constructor: -> | |
$(window).scroll @scroll | |
@targets = $ '.targets' | |
@sensitivity = 20 | |
showNavFor: (target)=> | |
name = $(target).attr 'name' | |
$('.active').removeClass 'active' | |
$("a[href=##{name}]").addClass('active'); | |
near: (target)=> | |
window.scrollY - @sensitivity < target.offset().top < window.scrollY + @sensitivity | |
scroll: (event)=> | |
for target in @targets | |
@showNavFor target if @near target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment