offset property Null safety

Point<num> offset

The coordinates of the mouse pointer in target node coordinates.

This value may vary between platforms if the target node moves after the event has fired or if the element has CSS transforms affecting it.

Implementation

Point get offset {
  if (JS('bool', '!!#.offsetX', this)) {
    var x = JS('int', '#.offsetX', this);
    var y = JS('int', '#.offsetY', this);
    return new Point(x as num, y as num);
  } else {
    // Firefox does not support offsetX.
    if (!(this.target is Element)) {
      throw new UnsupportedError('offsetX is only supported on elements');
    }
    Element target = this.target as Element;
    var point = (this.client - target.getBoundingClientRect().topLeft);
    return new Point(point.x.toInt(), point.y.toInt());
  }
}