Last active
October 3, 2022 19:21
-
-
Save agragregra/867576dc9498f9912e4de9919f060e0e to your computer and use it in GitHub Desktop.
CSS Target Without Jumping | Hash Change Without Jump
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
// Original | |
var hashLinks = document.querySelectorAll("a[href^='#']"); | |
[].forEach.call(hashLinks, function (link) { | |
link.addEventListener("click", function (event) { | |
event.preventDefault(); | |
history.pushState({}, "", link.href); | |
history.pushState({}, "", link.href); | |
history.back(); | |
}); | |
}); | |
// Uglify: | |
var hashLinks=document.querySelectorAll("a[href^='#']");[].forEach.call(hashLinks,function(e){e.addEventListener("click",function(t){t.preventDefault(),history.pushState({},"",e.href),history.pushState({},"",e.href),history.back()})}); | |
// Author: https://medium.com/@pimterry |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment