Skip to content

Commit

Permalink
Fix smooth scroll breaking back button #1767
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljl authored and edemaine committed Jan 4, 2019
1 parent 9232a38 commit 0a1dfc3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
23 changes: 22 additions & 1 deletion assets/js/_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,28 @@ $(document).ready(function() {
});

// init smooth scroll
$("a").smoothScroll({ offset: -20 });

// Bind the hashchange event listener
$(window).bind("hashchange", function (event) {
$.smoothScroll({
// Replace '#/' with '#' to go to the correct target
scrollTarget: location.hash.replace(/^\#\/?/, "#"),
offset: -20
});
});
$('a[href*="#"]').bind("click", function (event) {
// Remove '#' from the hash.
var hash = this.hash.replace(/^#/, "");
if (this.pathname === location.pathname && hash) {
event.preventDefault();
// Change '#' (removed above) to '#/' so it doesn't jump without the smooth scrolling
location.hash = "#/" + hash;
}
});
// Trigger hashchange event on page load if there is a hash in the URL.
if (location.hash) {
$(window).trigger("hashchange");
}

// add lightbox class to all image links
$(
Expand Down
Loading

0 comments on commit 0a1dfc3

Please sign in to comment.