Smooth Scroll To

Sometimes it’s difficult to find something you want to do that is very easy without a bunch of bells and whistles. In this case, you want a simple scroll to that is smooth and requires very little code. Here’s an option that requires 2 lines of code.

1. Put a div somewhere that you want to scroll to

<div id="div_scrollhere"></div>

2. Using JQuery, call it

$("html,body").animate({ scrollTop: $("#div_scrollhere").offset().top }, 1000);

You can play around with the speed options, 1000, 2000, 3000 and so on to get your scroll speed just right. You can also use shortcuts like ‘slow’ or ‘fast’.

Advertisements
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: