Reply To: Offset anchors with fixed header

Home Forums Support Offset anchors with fixed header Reply To: Offset anchors with fixed header

#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.