I have a fixed header at the top of my page. When it scrolls, I want to ensure that it does not cover or hide any of my content, especially the top portion of the section.
// This code enables smooth scrolling (source: css-tricks)
$('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
}, 1000);
return false;
}
}
});
For example, you can view a screenshot here.
I have made some CSS changes by adding padding and margins, but I am not completely satisfied with the result.
If possible, I would like the height of the fixed header to act as a top offset.
You can see the desired result similar to what I want in this example image.