Web developer, Norwich - Clive Portman

Scroll to top of element using jQuery

Published under Javascript, jQuery

Published on Monday 21st May 2012

Takes the distance between the top of the browser window and the element in question, then scrolls upwards. I subtract 100 so it doesn't quite scroll to the top.

var offset = $('#casestudies').offset();
$("html").animate({scrollTop:offset.top - 100},900);