Skip to content

Instantly share code, notes, and snippets.

@jeremymouton
Last active January 17, 2017 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremymouton/2f94ba0923e3c88efe73 to your computer and use it in GitHub Desktop.
Save jeremymouton/2f94ba0923e3c88efe73 to your computer and use it in GitHub Desktop.
jQuery Scroll To with offset support
/**
* Scroll To
* data-scroll-to="#element" or href="#element"
* data-scroll-to-offset="-10"
*/
import $ from 'jquery'
$('.js-scroll-to').on('click', function(e) {
e.preventDefault()
var target = $(this).data('scroll-to') || $(this).attr('href'),
offset = $(this).data('scroll-to-offset') || 0
$('html, body').animate({
scrollTop: $(target).offset().top + offset
}, 800)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment