$('input, select, textarea').on('focus', function() {; var that = $(this); $('html, body').animate({ scrollTop: that.offset().top + that.height() / 2 - $(window).height() / 2 }, 2000); }); $('body,html').bind('scroll mousedown wheel DOMMouseScroll mousewheel keyup', function(e) { if (e.which > 0 || e.type == "mousedown" || e.type == "mousewheel") { $("html,body").stop(); } });