If you use links to navigate to other elements on the same page, it’s generally a good idea to animate the scrolling so you don’t disorientate your users. There are jQuery plugins (such as ScrollTo) that offer many different ways for handling this, but if you don’t want to mess about with all the features of a new plugin then this snippet will be very useful. It’s a simple function that will scroll your page to any DOM element that you specify:

As you can see you can also specify the speed and a top offset for the scroll (I find this top offset very useful as default behaviour puts the target element flush with the top of the browser, which can make things feel a bit cramped). An added bonus is that it appends the target string to the current URL, so if you are using a standard anchor reference (such as #element) then users will be able to grab the URL and it will point to the correct location on the page. If you are using other selectors to target an element then I would recommend removing the function inside the animate call.