Skip to content

Instantly share code, notes, and snippets.

@agragregra
Last active October 3, 2022 19:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save agragregra/867576dc9498f9912e4de9919f060e0e to your computer and use it in GitHub Desktop.
Save agragregra/867576dc9498f9912e4de9919f060e0e to your computer and use it in GitHub Desktop.
CSS Target Without Jumping | Hash Change Without Jump
// 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