Home › Forums › Support › Offset anchors with fixed header › Reply To: Offset anchors with fixed header
September 19, 2016 at 10:57 pm
#227850
Tom
Lead Developer
Lead Developer
I personally use this code:
<script>
jQuery(function($) {
$('a.smooth[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 - 60
}, 500);
return false;
}
}
});
});
</script>
Then give your links a class of smooth
.
The 60
in the code is the amount of pixels to offset.