getElementWidth function

int? getElementWidth(
  1. Element element, [
  2. int? def
])

Returns element width. Tries to use 'offsetWidth' or 'style.width' values.

def default value if width is null or 0.

Implementation

int? getElementWidth(Element element, [int? def]) {
  var w = element.offsetWidth;
  if (w <= 0) {
    w = parseCSSLength(element.style.width, unit: 'px', def: def ?? 0) as int;
  }
  return w <= 0 ? def : w;
}