There are many examples of smooth scrolling using JS libraries such as jQuery, Mootools, Prototype, etc.
The following example is presented in pure JavaScript. If you do not have jQuery / Mootools / Prototype on the page or you do not want to overload the page with heavy JS libraries, this example will help.
http://jsfiddle.net/rjSfP/
HTML part:
<div class="first"><button type="button" onclick="smoothScroll(document.getElementById('second'))">Click Me!</button></div> <div class="second" id="second">Hi</div>
CSS part:
.first { width: 100%; height: 1000px; background: #ccc; } .second { width: 100%; height: 1000px; background: #999; }
JS Part:
window.smoothScroll = function(target) { var scrollContainer = target; do {
nico Aug 6 '13 at 4:30 2013-08-06 04:30
source share