Skip to content

Instantly share code, notes, and snippets.

@atleastimtrying
Last active December 10, 2015 22:39
Show Gist options
  • Save atleastimtrying/4504130 to your computer and use it in GitHub Desktop.
Save atleastimtrying/4504130 to your computer and use it in GitHub Desktop.
a basic scroll position detector
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