Last active
August 29, 2015 14:07
-
-
Save erikpukinskis/2574a5e2f093db7fa700 to your computer and use it in GitHub Desktop.
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
| function scrollToReveal(selector) { | |
| MINIMUM = 50 | |
| function scrollTowards(edge) { | |
| var distance = distanceTo(edge, selector) | |
| if (distance > MINIMUM) { return } | |
| var offset = distance - MINIMUM | |
| var direction = directionTowards(edge) | |
| var newPosition = $('body').scrollTop() - direction * offset | |
| $('html,body').scrollTop(newPosition) | |
| } | |
| function directionTowards(edge) { | |
| return edge == 'bottom' ? 1 : -1 | |
| } | |
| scrollTowards('bottom') | |
| scrollTowards('top') | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment