Created
June 11, 2013 19:09
-
-
Save marceloxp/5759727 to your computer and use it in GitHub Desktop.
setToCenterOfParent
This file contains 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 setToCenterOfParent(obj, parentObj) | |
{ | |
var height = $( obj ).height(); | |
var width = $( obj ).width(); | |
if ( parentObj == window ) { | |
$( obj ).css( 'top', ( $( parentObj ).height() / 2 ) - ( height / 2 ) ); | |
$( obj ).css( 'left', ( $( parentObj ).width() / 2 ) - ( width / 2 ) ); | |
} | |
else { | |
$( obj ).css( 'top', ( $( parentObj ).height() / 2 ) - ( height / 2 ) + $( parentObj ).position().top ); | |
$( obj ).css( 'left', ( $( parentObj ).width() / 2 ) - ( width / 2 ) + $( parentObj ).position().left ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment