var linkHandler = function(ev) { if (!ev.defaultPrevented) { ev.preventDefault();
if (location.hash !== this.hash) window.history.pushState(null, null, this.hash) // using the history api to solve issue #1 - back doesn't work // most browser don't update :target when the history api is used: // THIS IS A BUG FROM THE BROWSERS. // change the scrolling duration in this call var node = document.getElementById(this.hash.substring(1)) if (!node) return; // Do not scroll to non-existing node
smoothScroll(node, 500, function (el) { location.replace('#' + el.id) // this will cause the :target to be activated. }); } }
var linkHandler = function(ev) { if (!ev.defaultPrevented) { ev.preventDefault();
if (decodeURIComponent(location.hash) !== decodeURIComponent(this.hash)) window.history.pushState(null, null, decodeURIComponent(this.hash)) // using the history api to solve issue #1 - back doesn't work // most browser don't update :target when the history api is used: // THIS IS A BUG FROM THE BROWSERS. // change the scrolling duration in this call var node = document.getElementById(decodeURIComponent(this.hash).substring(1)) if (!node) return; // Do not scroll to non-existing node
smoothScroll(node, 500, function (el) { location.replace('#' + el.id) // this will cause the :target to be activated. }); } }