Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.