Skip to content

Instantly share code, notes, and snippets.

@s-hiroshi
Created February 25, 2012 07:49
Show Gist options
  • Save s-hiroshi/1907275 to your computer and use it in GitHub Desktop.
Save s-hiroshi/1907275 to your computer and use it in GitHub Desktop.
jQuery > calculate offset
function getOffset(inner, outer) {
// オフセット
var offsetX = Math.ceil(($(outer).width() - $(inner).width()) / 2);
var offsetY = Math.ceil(($(outer).height - $(inner).height()) / 2);
var offset = {
x: offsetX,
y: offsetY
};
return offset;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment