I want to use a smooth scroll for my nav-links, but I am having a fixed nav, so I have to change the landing position a little bit. Now I found the answer in this forum and it looks like this:
$(document).ready(function(){
$('a[href^="#"]').on('click',function (e) {
e.preventDefault();
var target = this.hash;
$target = $(target);
$('html, body').stop().animate({
'scrollTop': $target.offset().top-100
}, 900, 'swing', function () {
window.location.hash = target;
});
});
});
The "top-100" should work, but it just doesn't... Does anybody have an idea? Thanks
Use
partseInt
to always use theint
value in browsers.Syntax
jQuery