function log(n, x, y) {
out.textContent = `${n}@${Math.ceil(x)}x${Math.ceil(y)}`;
}
function sq(a) {return a*a }
let matrix;
root.addEventListener('pointermove', function(e) {
if (!e.target.id) {
return undefined;
}
if (root === e.target) {
log(e.target.id, e.offsetX, e.offsetY);
e.stopImmediatePropagation();
return false;
}
// local to global :)
if (!matrix) {
let currentElement = e.target;
matrix = new DOMMatrix(); // id
while (currentElement) {
let currentMatrix = new DOMMatrix(window.getComputedStyle(currentElement).transform);
if (!currentMatrix.isIdentity) {
// Rotation and translation seem to be taken
// care of by the browser, but not *scale*.
// Decompose the scale from currentMatrix:
let sx = Math.sqrt(sq(currentMatrix.m11) + sq(currentMatrix.m12) + sq(currentMatrix.m13));
let sy = Math.sqrt(sq(currentMatrix.m21) + sq(currentMatrix.m22) + sq(currentMatrix.m23));
let sz = Math.sqrt(sq(currentMatrix.m31) + sq(currentMatrix.m32) + sq(currentMatrix.m33));
// Scale matrix by sx, sy, sz:
matrix = matrix.scaleNonUniform(sx, sy, sz);
}
currentElement = currentElement.parentElement;
}
console.log(matrix);
}
// We need to apply the matrix transform to the point
// reported by the event, to get its "true" coordinates!
let newCoords = matrix.transformPoint(new DOMPoint(e.offsetX, e.offsetY));
log(e.target.id, newCoords.x, newCoords.y);
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.