Last active
May 14, 2018 16:07
-
-
Save celsowhite/772f8f10d34efd0695d550260636176c to your computer and use it in GitHub Desktop.
Smooth scroll links. Uses event delegation.
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
/*---------------------------- | |
SMOOTH SCROLL | |
----------------------------*/ | |
$( "body" ).on( "click", ".smooth_scroll", function() { | |
// Breakpoint to adjust the offset distance. | |
const tabletLandscapeBreakpoint = window.matchMedia("(max-width: 1024px)"); | |
// Get the target element & set normal offset | |
let target = $(this).attr('data-target'); | |
let offsetDistance = -80; | |
// If below our breakpoint then adjust offset for a smaller mobile header | |
if (tabletLandscapeBreakpoint.matches) { | |
offsetDistance = -60; | |
} | |
target = $('#' + target); | |
$('html, body').animate({ | |
scrollTop: target.offset().top + offsetDistance, | |
}, 1000); | |
return false; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment