JSFiddle - React, Tailwind, and code Playground
by TJ VanToll
HTML
<link href="http://code.jquery.com/ui/jquery-ui-git.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-git.js"></script>
<script src="http://code.jquery.com/ui/jquery-ui-git.js"></script>
<input type="text" />
CSS
input{ margin-top: 3000px; }
JavaScript
$.widget( "ui.dialog", $.ui.dialog, {
close: function( event ) {
var openerScrollParent = this.opener.scrollParent(),
scrollTop = openerScrollParent.scrollTop(),
scrollLeft = openerScrollParent.scrollLeft();
this._super( event );
openerScrollParent.scrollTop( scrollTop ).scrollLeft( scrollLeft );
}
});
$('input').focus();
$(document.body).scrollTop(0);
$("<div>closing me restores focus to the previously-focused element, which on some (most? all?) browsers has the side effect of moving it into view... even if it wasn't in view before</div>").dialog();