Skip to content

Instantly share code, notes, and snippets.

@bgadrian
Created March 16, 2015 17:00
Show Gist options
  • Save bgadrian/cdecd31ffc8ead10bdb6 to your computer and use it in GitHub Desktop.
Save bgadrian/cdecd31ffc8ead10bdb6 to your computer and use it in GitHub Desktop.
Script JS center vertical window - on center of a div
/** Center the browser vertically on the game board */
var centerBrowserGameBoard = function()
{
var w_height = $j(window).height();
var table_top = $j('#div').offset().top;
var table_height = $j('#div').height();
//if no need to scroll - the table is visible
if (!force && w_height > (table_top + table_height))
{
return false;
}
$j(document).scrollTop(
//go to middle
table_top + table_height / 2
//now go up half of window
- w_height / 2
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment