Skip to content

Instantly share code, notes, and snippets.

@erikpukinskis
Last active August 29, 2015 14:07
Show Gist options
  • Save erikpukinskis/2574a5e2f093db7fa700 to your computer and use it in GitHub Desktop.
Save erikpukinskis/2574a5e2f093db7fa700 to your computer and use it in GitHub Desktop.
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