question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[DOM] Element position doesn't get computed properly when `iframe` gets scaled

See original GitHub issue

I have an element inside an iframe, and I’m trying to compute its position from the parent window. However, when I give transform: scale(2) to iframe element, scale doesn’t get counted. https://codesandbox.io/s/floating-ui-dom-template-forked-gz4whh?file=/src/index.js

This is how the tooltip gets rendered: image

Instead, I was expecting something like this: image

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
jpertermcommented, Aug 23, 2022

Hi, I just wanted to mention that I have the same issue with scaling. I get extra x-/y-shifting and the higher the position of the context elements the higher is the extra x-/y-shifting.

It seems that this use-case often comes with sections of a webapp that have a scaling feature. From my side an opportunity to feed the computePosition function with x-/y-scaling numbers is sufficient as I know where those scalings are applied. But there may be others cases for which it is not.

0reactions
atomikscommented, Dec 16, 2022

Okay so at this point, scale issues are killing me 🥲, there were 5 releases (1.0.8-1.0.12) fixing various issues with transform/scale, but I did find a solution to this iframe issue with the getScale function we now have.

Apply it to these values as @seahindeniz originally suggested:

https://github.com/floating-ui/floating-ui/blob/99d187876a42fbd7057952d3b273c0978d562770/packages/dom/src/utils/getBoundingClientRect.ts#L28-L37

  const iframe = element.ownerDocument?.defaultView?.frameElement;
  const iframeScale = iframe ? getScale(iframe) : {x: 1, y: 1};

  x *= iframeScale.x;
  y *= iframeScale.y;
  width *= iframeScale.x;
  height *= iframeScale.y;
Read more comments on GitHub >

github_iconTop Results From Across the Web

Adjust width and height of iframe to fit with content in it
This works beautifully if the parent document and document in the iframe are both from the same domain.
Read more >
<iframe>: The Inline Frame element - HTML - MDN Web Docs
Positioning and scaling​​ As a replaced element, the position, alignment, and scaling of the embedded document within the <iframe> element's box, ...
Read more >
How to Scale the Content of <iframe> Element - W3docs
Scaling the content of an may be needed if you want to display an object in the area not matching its original size....
Read more >
Linearly Scale font-size with CSS clamp() Based on the Viewport
What we are trying to achieve with clamp() is called linear interpolation: getting intermediate information between two data points.
Read more >
Embedded Content — SVG 2
Computation of automatically-sized values follows the Default Sizing Algorithm defined for replaced elements in CSS layout [css-images-3]. In particular, when ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found