<div class="bad_transform">
<div class="transform">
<div class="app">
<!-- This has a shadowRoot -->
<!-- irrelevant for the problem
<div class="custom-content" slot="content">
Hover over this, <tt>(x, y)</tt> will reset to 0,0!
</div>
-->
</div>
</div>
</div>
<!-- Force scroll and render debug info -->
<div class="far">
And here, some content so the above can scroll!
</div>
<div id="output">x: ?<br />y: ?</div>
<div id="graphicalDebug"></div>
// Current API reimplementation of:
// https://gist.github.com/Yaffle/1145197
// This code works if the 4th column of the matrix3d (perspective) is set to (0, 0, 0, 1)
// Reading: https://www.scratchapixel.com/lessons/3d-basic-rendering/computing-pixel-coordinates-of-3d-point
// More: https://dev.opera.com/articles/understanding-the-css-transforms-matrix
// AKA: convertPointFromPageToNode
let identity = new DOMMatrixReadOnly();
// Recursively computes the perspective matrix from `element` to the
// root of the page.
// If E is the element and P, GP, GGP are its Parent/GrandParent/GreatGrandPa
// This function composes the transform matrix like so:
// GPP*(GP*(P*E)) by multiplying matrices from left to right as the algo
// walks up the DOM tree.
function getCssTransforms(element) {
let current = element;
let transforms = identity;
while (current != null && current !== current.ownerDocument.documentElement) {
let computedStyle = window.getComputedStyle(current);
let transform = new DOMMatrixReadOnly(computedStyle.transform);
let origin = computedStyle.transformOrigin;
if (!transform.isIdentity) {
transforms = transform.multiply(transforms);
}
current = current.parentNode;
}
return transforms;
}
// Computes the transform matrix applied to `element`, including a global
// translation before applying the perspective matrix `transforms`.
function getTransformMatrix(element, transforms) {
// Attempt to figure out the transformed top-left coordinates
// of `element` to compute the translation applied from the
// outside? (margins, paddings, and friends?)
let w = element.offsetWidth; // post transform
let h = element.offsetHeight; // post transform
let p1 = transforms.transformPoint(new DOMPoint(0, 0));
let p2 = transforms.transformPoint(new DOMPoint(w, 0));
let p3 = transforms.transformPoint(new DOMPoint(w, h));
let p4 = transforms.transformPoint(new DOMPoint(0, h));
let left = Math.min(p1.x/p1.w, p2.x/p2.w,...
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.