jQuery: the scrollTop() method
HTML
<p><button id="scroll">scrollTop()</button></p>
<div id="test"></div>
CSS
#test {
width: 100px;
height: 100px;
position: relative;
top: 1000px;
background: green;
}
JavaScript
$('#scroll').click(function() {
$('html,body').animate({
scrollTop: $('#test').css('top')
// scrollTop: $("#test").offset().top
}, 800, function() {
$('html, body').animate({
scrollTop: 0
}, 800);
});
});