Created
March 16, 2015 17:00
-
-
Save bgadrian/cdecd31ffc8ead10bdb6 to your computer and use it in GitHub Desktop.
Script JS center vertical window - on center of a div
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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