Reputation: 6246
I have this Fiddle to make a smooth scroll
$('#up, #down').on('click', function(e){
e.preventDefault();
var the_id = $(this).attr("href");
$('html, body').stop().animate({
scrollTop : $(the_id).offset().top
}, 500);
});
and it's execute perfectly but i didn't undestand this line :
scrollTop : $(the_id).offset().top
Because the scroll is up and down, and i see nothing like
scrollDown : $(the_id).offset().down
Upvotes: 0
Views: 35
Reputation: 5784
This piece of code just indicates the height from the top of your page.
scrollTop : $(the_id).offset().top
You could add some css to this to start at for example 40px from the top with margin-top: 40px;
It's just 'the top of the page' in easy words.
Upvotes: 1
Reputation: 2805
It's called scrollTop because it's the distance from the top of the page, so there's no need for a scrollDown.
The code just rapidly changes the value of scrollTop so that the page scrolls smoothly to the given position.
Upvotes: 2