1
Fork 0

Target all anchor links and only scroll when target exists

This commit is contained in:
Jake Howard 2020-08-13 20:13:21 +01:00
parent 601e443b3b
commit e920b646c0
Signed by: jake
GPG key ID: 57AFB45680EDD477

View file

@ -77,10 +77,12 @@ $('#scroll-top').on('click', function(event) {
scrollTo(0); scrollTo(0);
}); });
$('#TableOfContents a').on('click', function(event) { $('a[href^="#"] ').on('click', function(event) {
event.preventDefault(); event.preventDefault();
const target = $($(this).attr('href')); const target = $($(this).attr('href'));
scrollTo(target.offset().top); if (target.length) {
scrollTo(target.offset().top);
}
}); });
$('[data-clipboard-text]').on('click', function(event) { $('[data-clipboard-text]').on('click', function(event) {