W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2010

[DOM Level 3 Events] MouseEvent.getCoordsAt(element)

From: Jonathan Watt <jwatt@jwatt.org>
Date: Tue, 05 Oct 2010 11:06:04 +0100
Message-ID: <4CAAF88C.6000307@jwatt.org>
To: www-dom@w3.org
Hi WG,


Positioning elements based off the position of a pointer event is regularly
tripping people up in SVG, and with the advent of CSS-transforms, I imagine also
in HTML.

To position an element based off the position of a pointer event you need to get
the coordinates of the event in the local coordinate system of the element. To
do that currently authors have to get the *correct* element-to-root transform,
invert it, create an SVGPoint, copy the event coordinates to the SVGPoint, then
use the inverted transform to transform the point and read back the coordinates.
For something so simple, it's not obvious that this is what you need to do, or
even how to do it.


To make life easier for authors I'd like to propose the addition of a
'getCoordsAt' method to the MouseEvent interface. This method would be passed
the element at which the local coordinates of the event are required, and return
an object implementing the SVGPoint interface[1] (or a new interface
implementing 'x' and 'y' properties).

I've uploaded a JavaScript implemented demo of this method here:


See also the comments in the source code.


[1] http://www.w3.org/TR/SVG11/coords.html#InterfaceSVGPoint
Received on Tuesday, 5 October 2010 10:06:43 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:36:57 UTC