Reputation: 23
Just starting out with jquery. I have written the following function:
jQuery(document).ready(function($){
$('.tb-to-side-menu > li > a').on('click', function() {
$('html, body').animate({
scrollTop: $(this.hash).offset().top
}, 1000);
return false;
});
});
This is for a 'one page' styled site, so when the use clicks on the nav they get smooth scrolling down. Problem is that I have a sticky nav and the content is sliding too far up. Is it possible to add a css class in with jquery that allows for the height of my nav div?
Thanks
Upvotes: 0
Views: 34
Reputation: 337560
If I've understood the issue, you could subtract the height of the fixed header from $(this.hash).offset().top
, for example:
$('html, body').animate({
scrollTop: $(this.hash).offset().top - $('#fixedHeader').height()
}, 1000);
Upvotes: 2