Created
July 9, 2012 03:02
-
-
Save tnip/3074000 to your computer and use it in GitHub Desktop.
Vertically Centering Things in JS
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
function verticallyAlignTheDamnThing(){ | |
var content_height = $(‘#centered-element’).height(); | |
var window_height = $(document).height(); | |
// Reposition the div vertically! | |
var reposition_top_y = (window_height - content_height) / 2; | |
if(reposition_top_y > 0){ | |
$(‘#centered-element’).css(‘margin-top’, reposition_top_y + ‘px’); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment