Skip to content

Instantly share code, notes, and snippets.

@junosuarez
Created December 11, 2012 05:33
Show Gist options
  • Save junosuarez/4256134 to your computer and use it in GitHub Desktop.
Save junosuarez/4256134 to your computer and use it in GitHub Desktop.
box size
function boxSize($el) {
var box = {};
box.width = $el.width();
box.height = $el.height();
_.forEach(['margin', 'padding'], function (prop) {
box[prop] = {};
_.forEach(['top','left','bottom','right'], function (dir) {
box[prop][dir] = parseInt($el.css(prop + '-' + dir));
});
});
box.outerWidth = box.width + box.margin.right + box.margin.left + box.padding.left + box.padding.right;
box.outerHeight = box.height + box.margin.top + box.margin.bottom + box.padding.top + box.padding.bottom;
return box;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment