I've been developing an HTML5 application and now I'm facing quite a difficult problem getting a proper local touch / mouse position inside a target div in a proper coordinate system.
There are many solutions on StackOverflow but the thing is not so easy.
The "classical" solution is to compute a target offset and subtract it from pageX and pageY position. Many people use JQuery offset
function but we have found it buggy (1.8.3) on iOS in some situations when the page is scrolled and contains nested zoomed divs.
The situation is event more complicated because there are not only nested zoomed divs (CSS zoom
property) but also layers with different CSS transformations (x and y translations).
Finally we have written our own function to compute the local mouse / touch position in a target div (using WebKitCSSMatrix
, MSCSSMatrix
and others...). It works 'almost' well but still not perfect is some situations - especially when there are nested zoomed divs.
So my question is whether there is some general solution / library to compute a local touch / mouse position inside a target div considering the above described requirements??
Thanks.
Nice day to all...