I want to create navigation with anchor URL' and smooth scroll. But on that page I use a sticky header with a height of 88px.
How can I create a smooth scroll, based on class product-anchor-links-action
?
JSFiddle: https://jsfiddle.net/rx0txmek/2/
My current HTML:
<div class="product-page-nav">
<div class="container">
<ol class="product-anchor-links-list">
<li class="product-anchor-links-item"><a href="#productbeschrijving" class="product-anchor-links-action">Nav 1</a></li>
<li class="product-anchor-links-item"><a href="#specificaties" class="product-anchor-links-action">Nav 2</a></li>
<li class="product-anchor-links-item"><a href="#reviews" class="product-anchor-links-action">Nav 3</a></li>
</ol>
</div>
</div>
jQuery:
$(function() {
$('a[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html, body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});