Last active
August 29, 2015 14:02
-
-
Save AaronLayton/6ba2ce63fff89ac44276 to your computer and use it in GitHub Desktop.
This file contains 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
/*============================================================= | |
e.g. <div class="scrollhere"></div> | |
<a data-scroll="scrollhere" href="#"></a> | |
TODO Detect whether class or id without indication | |
Allow class="js-scroll-{element}" to initiate | |
==============================================================*/ | |
function scrollToModule() { | |
$(document).on('click', '[data-scroll]', function (e) { | |
e.preventDefault(); | |
// Get all the data in one place | |
var elm = $($(this).data('scroll')), | |
scrollSpeed = parseInt($(this).data('speed')) || 300, | |
scrollOffset = 0; | |
// If we have an element to scroll to then grab the offset | |
if (elm.length) scrollOffset = elm.offset().top; | |
// Now lets scroll | |
$('html:not(:animated),body:not(:animated)').animate({ | |
scrollTop: scrollOffset | |
}, scrollSpeed); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment