Skip to content

Instantly share code, notes, and snippets.

@marceloxp
Created June 11, 2013 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marceloxp/5759727 to your computer and use it in GitHub Desktop.
Save marceloxp/5759727 to your computer and use it in GitHub Desktop.
setToCenterOfParent
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