Skip to content

Instantly share code, notes, and snippets.

@wplit
Last active August 5, 2020 11:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wplit/56632b0016282eb85811dde679e55482 to your computer and use it in GitHub Desktop.
Save wplit/56632b0016282eb85811dde679e55482 to your computer and use it in GitHub Desktop.
scroll with id and offset (and fix for comment reply links not working)
jQuery(document).ready(function($) {
const offset = 0, // change offset (px)
scrollTime = 300; // change scrolling animation time (ms)
$('a[href*="#"]').not('[href="#"]').not('[href="#0"]').not('[href*="replytocom"]').click(function (t) {
if (location.pathname.replace(/^\//, "") == this.pathname.replace(/^\//, "") && location.hostname == this.hostname) {
var e = $(this.hash);
(e = e.length ? e : $("[name=" + this.hash.slice(1) + "]")).length && (t.preventDefault(), $("html, body").animate({ scrollTop: e.offset().top - offset }, scrollTime));
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment