prototypejs / prototype

Prototype JavaScript framework
http://prototypejs.org/
Other
3.53k stars 639 forks source link

Position.within fails when parent dom tree contains css transformations #322

Open qsiebers opened 7 years ago

qsiebers commented 7 years ago

Position.within fails to take into account transformations performed by the CSS transform properties. The cause is probably located within Element.cumulativeOffset.

I'm not sure on how to fix this, or if it's even wanted.

savetheclocktower commented 7 years ago

Yeah, not sure there's much to do about that. Last time I checked (though it's been a few years) there wasn't a reliable way to figure out where an element was on the screen with transforms taken into account. Properties like offsetLeft don't "see" transforms, and even stuff like getBoundingClientRect didn't behave uniformly across browsers when transforms are applied.

But I should check again, so I'll leave this open for now.

qsiebers commented 7 years ago

It seems you can use window.getComputedStyle() to get the transformation matrix. You can then calculate the new transformed position of the element. I think I'll change my own workaround to use the translate values provided by the matrix.

It might be a nice feature to use all the transformation matrix information in calculating correct location, although this would hardly be optimal unless there is a way to get this information directly from the browser.