Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Images are not zoomed in the center of the viewport when document is displayed within an iframe #312

Open
PiiXiieeS opened this issue Oct 10, 2020 · 3 comments
Labels

Comments

@PiiXiieeS
Copy link

Images are not zoomed in the center of the viewport
When zooming is used in a site embedded as an iframe the zooming effect while works it is not positioned in the center of the visible part of the window.

To Reproduce
Simple embed a page as an iframe resizing the frameHeight to be equal to the full size of the child content.

    <iframe
      id="cpv-iframe"
      class="myframe"
      width="100%"
      height="1000px"
      :src="url"
      @load="load('cpv-iframe')"
    >
    </iframe>

with load ...

    load(id) {
      window.onmessage = (e) => {
        if (Object.prototype.hasOwnProperty.call(e.data, 'frameHeight')) {
          document.getElementById(id).style.height = `${
            e.data.frameHeight + 30
          }px`
        }
      }
    },

Expected behavior
The image should zoom and center in the visible part of the document within the iframe.
The function getWindowCenter is not retrieving the center of the window but the center of the full document/iframe.

Additional context
Any help or direction to implement this fix so the zoom effect works also inside an iframe is welcome and I will try to implement and to make a pull request.

@PiiXiieeS PiiXiieeS added the bug label Oct 10, 2020
@kingdido999
Copy link
Owner

Would it be possible for you to reproduce this issue in codepen?

@PiiXiieeS
Copy link
Author

Here you are:
https://codepen.io/piixiiees/pen/abZOJzJ

@kingdido999
Copy link
Owner

Thanks! I don't have much bandwidth to work on this, but feel free to give it a try.

You probably want to begin with understanding the Zooming.open() method, more specifically these method calls which basically translate & transform the target image and then inject the overlay element. We're currently calculating the transformation and inserting the overlay based on the element's document window, that's why we faced this issue. Therefore, we need to do those operations against the root window instead of the iframe window. I guess one key thing is to get the position of the image relative to the root window instead of the iframe window, which might not be very straightforward.

Anyway, that's my thoughts and if you still want to give it a shot, feel free to do so and let me know if you have any questions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants