Home › Forums › JavaScript › smooth anchor link scroll, anchor point sticky header compensation, etc. › Reply To: smooth anchor link scroll, anchor point sticky header compensation, etc.
Well, that must be something to do with the code getting parsed – if I copy and paste the original and run it on your site it seems to work.
https://css-tricks.com/snippets/jquery/smooth-scrolling/
I did notice the ampersands (&&
) are transformed and a couple of backslashes missing. I am not sure where the latter got lost when I posted the previous code. Are you uploading it directly with ftp?
$(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-68 // right here
}, 1000);
return false;
}
}
});
});
Just testing this to see what happens…
Conclusion – the backslashes get stripped from the code when posted. So please copy and paste from the link – and don’t forget to account for the 68 pixels in the correct place.