user3386779
user3386779

Reputation: 7205

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');

Upvotes: 1

Views: 49

Answers (1)

Dennis Novac
Dennis Novac

Reputation: 1011

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');

Upvotes: 3

Related Questions