How can I modify my script so that it stops 50px above my target DIV. This is because I have a fixed nav bar on top of the screen that is 50px wide and would like it to be taken into account.
$(document).ready(function(){
$("a").on('click', function(event) {
if (this.hash !== "") {
event.preventDefault();
var hash = this.hash;
$('html, body').animate({
scrollTop: $(hash).offset().top
}, 800, function(){
window.location.hash = hash;
});
}
});
});
try this this what worked In my case
where 50 is height of you header. Instead You can also use