JavaScript offre un semplice modo per ottenere la larghezza esterna del box contenitore di un elemento compresi i margini.
La soluzione รจ la seguente:
const outerWidth = element => {
let width = 0;
if(element === null || !element) {
return width;
}
const style = getComputedStyle(element);
width += element.offsetWidth + parseInt(style.marginLeft,10) + parseInt(style.marginRight,10);
return width;
};