Im trying to get the document(global) coordinates of an Element (DOM Element) in Dart, which in pure JavaScript I was able to get via jQuery with $('some_selector').offset().
Ive been looking through the Dart dart:html API's, but no luck so far.
any ideas? thanks
There's no native function on Element to get that coordinates.
Here's a Dart's version of jQuery.offset() :
class Position {
num left, top;
Position(this.left, this.top);
}
Position offset(Element elem) {
final docElem = document.documentElement;
final box = elem.getBoundingClientRect();
return new Position(box.left + window.pageXOffset - docElem.clientLeft,
box.top + window.pageYOffset - docElem.clientTop);
}
An other solution is to use jQuery.offset() via js-interop :
Position jQueryOffset(Element elem) {
return js.scoped((){
final offset = js.context.jQuery(elem).offset();
return new Position(offset.left, offset.top);
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With