Last active
December 17, 2022 10:23
-
-
Save iamrobert/a47a8a6f0f1814f8b2616ec912b969f8 to your computer and use it in GitHub Desktop.
Locomotive JS gists - #anchor scrolls and tabs
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
/* + LOCOMOTIVE ANCHORS | |
https://github.com/locomotivemtl/locomotive-scroll/issues/175#issuecomment-1082541029 | |
======================================================================*/ | |
const anchorLinks = document.querySelectorAll('.mainbody a[href^=\\#]:not(.no-loco):not([href$=\\#])'); | |
anchorLinks.forEach((anchorLink) => { | |
let hashval = anchorLink.getAttribute('href'); | |
let target = document.querySelector(hashval); | |
anchorLink.addEventListener('click', (e) => { | |
e.preventDefault(); | |
e.stopPropagation(); | |
locoScroll.scrollTo(target); | |
// Adding a JUMP STATUS | |
let targetID = '#' + target.id; | |
if (targetID !== "#") { | |
history.pushState(null, null, targetID); | |
} | |
// | |
}); | |
}); | |
/* + LOCOMOTIVE TABS | |
====================================================================== */ | |
const tabsLinks = document.querySelectorAll('.mainbody a.js-tabs__trigger'); | |
tabsLinks.forEach((tabsLink) => { | |
tabsLink.addEventListener('click', (e) => { | |
locoScroll.update(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment