user3386779 user3386779 - 2 months ago 18
jQuery Question

scroll top to given position

I have fixed header for 16vh.I want to scroll my div 'sample' to top :16vh using jquery.I tried to scroll to top and stick after 16vh.
I want to leave 16vh space above after scroll. i.e)instead of stick to top 0 to stick to stick at 16vh.

$('html,body').animate({
scrollTop: $("#block-views-customerspeak-block").offset().top},
'0');

Answer

You basically need to extract the height of your header from whole height, something like this:

$('html,body').animate({
    scrollTop: $("#block-views-customerspeak-block").offset().top - $('.your-header').height()},
'0');
Comments