0

I have the following jQuery-script to scroll the page down.

$(document).ready(function() {

$('a[href^=#]').on('click', function(e){
    var href = $(this).attr('href');
    $('html, body').animate({
        scrollTop:$(href).offset().top
    },1500);
    e.preventDefault();
    });
});

The page has a fixed header with a height of 100px. Obviously I need to scroll down 100px less, so the header doesn't overlay the heading. I googled and I need to put in "{offset: -100}" somewhere.. but where?

1 Answer 1

5

Just reduce the header height from the scrollTop amount.

 $('html, body').animate({
   scrollTop: $(href).offset().top - $("header").outerHeight() + "px"
 }, 1500);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.