Last active
August 5, 2020 11:26
-
-
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)
This file contains hidden or 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
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