0

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

2
  • 1
    api.jquery.com/addclass Commented Feb 2, 2015 at 15:30
  • 1
    Thanks, works. Cheers Commented Feb 2, 2015 at 15:57

2 Answers 2

2

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);
Sign up to request clarification or add additional context in comments.

Comments

0

You can use: $(ele).addClass("classname")

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.