width
Version:
## License MIT © [Nil Késede](http://ksde.pw)
25 lines (19 loc) • 532 B
JavaScript
var querySelector = require('query-selector-all');
var isElement = require('is-element');
module.exports = function(element) {
var theWidth = 0;
if (typeof element == 'string') {
querySelector(element, function(el) {
theWidth = width(el);
});
} else if (isElement(element)) {
theWidth = width(element);
}
return theWidth;
};
function width(el) {
var width = el.offsetWidth;
var style = getComputedStyle(el);
width += parseInt(style.marginLeft) + parseInt(style.marginRight);
return width;
}