Created
October 5, 2013 01:38
-
-
Save phamquocbuu/6835557 to your computer and use it in GitHub Desktop.
JavaScript Set Center
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 setCenter(elm) { | |
w = $(window).width(); | |
lr = ( w - $(elm).width() ) / 2; | |
h = $(window).height(); | |
tb = ( h - $(elm).height() ) / 2; | |
$(elm).css({ | |
"margin-left" : lr, | |
"margin-right" : lr, | |
"margin-top" : tb, | |
"margin-bottom" : tb | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment