Skip to content Skip to sidebar Skip to footer

Smooth Scroll Anchor Jquery

I want to create navigation with anchor URL' and smooth scroll. But on that page I use a sticky header with a height of 88px. How can I create a smooth scroll, based on class produ

Solution 1:

Just subtract the height of the sticky header from the scrollTop value. When there is no sticky, the value will be 0 (you can just use the .height() value if the sticky is always present).

$('a').click(function(){

    var stickyHeight = $('.sticky').length ? $('.sticky').height() : 0

    $('html, body').animate({
        scrollTop: $( $(this).attr('href') ).offset().top - stickyHeight 
    }, 500);
    returnfalse;
});  

If there is no $('.stickyHeader')

Post a Comment for "Smooth Scroll Anchor Jquery"