1
2
3
4
5
6
function scrollGo() {
   var x = $(this).offset().top - 100; // 100 provides buffer in viewport
   $('html,body').animate({scrollTop: x}, 500);
}
// set focus event on element
$('#myForm :input').focus(scrollGo);