Last active
January 17, 2017 19:33
-
-
Save jeremymouton/2f94ba0923e3c88efe73 to your computer and use it in GitHub Desktop.
jQuery Scroll To with offset support
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
/** | |
* 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