jQuery Scroll page to position of an element/div

When you’re working with a complex page that has a load of areas on-screen, making use of this jQuery Scroll page to position of an element/div function below to scroll to the location will enhance you’re user experience by saving them needing to scroll… take them straight to it!

// This is a functions that scrolls to #id
function scrollTo(id)
{
  // Scroll
  $('html,body').animate({scrollTop: $("#"+id).offset().top},'slow');
}

Example usage:

$('#thing').click(function(e){
  scrollTo("divid");
});

Leave a Reply


The reCAPTCHA verification period has expired. Please reload the page.