user1444027
user1444027

Reputation: 5241

Add 100px space to scrolltop

I am using the following jQuery function to scroll to div IDs within a single page site:

$('a').click(function(){
    var top = $('html').find($(this).attr('href')).offset().top;
    $('html, body').animate({scrollTop: top},1500, 'easeInOutCubic');
    return false;
});

Is there a way to add 100 pixels of space above each div using jQuery?

I have a fixed position menu in the top of the browser window and need the divs to remain below the menu when scrolled to.

Upvotes: 1

Views: 10105

Answers (1)

Claudio Bredfeldt
Claudio Bredfeldt

Reputation: 1422

Not sure if I got the question right, but it sounds very easy to achieve:

...
var top = $('html').find($(this).attr('href')).offset().top - 100;
...

Upvotes: 9

Related Questions