Jump to content
Search Community

Flip with iFrame causes iFrame to rerender

PP-Tom test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

  • Solution

Good catch, @PP-Tom. That's an edge case that'd only occur when you call Flip.getState() on an element that has position: fixed and transform: none. GSAP was trying to apply a workaround that's normally necessary for an element that's not in the document flow because the browser won't report transforms accurately unless it's in the document flow. It has to temporarily reparent the element which is what was causing that iframe to reload. I've applied a workaround in the next release of GSAP which you can preview at:

https://assets.codepen.io/16327/gsap-latest-beta.min.js

 

In the meantime, you can use this function to fix it in older versions: 

// in GSAP 3.12.5 and earlier, Flip.getState() could cause an iframe to reload if the element was position: fixed and transform: none. This function applies a fix that basically just applies a translateX(0.01px) temporarily. 
function fixFlip() {
  let getState = Flip.getState;
  if (getState._fixed) return; // in case the fix was already applied
  Flip.getState = (targets, vars) => {
    let revert = [];
    gsap.utils.toArray(targets).forEach(target => {
      if (!target.offsetParent && gsap.getProperty(target, "transform") === "none") {
        revert.push(target);
        target.style.transform = "translateX(0.01px)";
      }
    });
    let state = getState(targets, vars);
    revert.forEach(t => t.style.transform = "none");
    return state;
  };
  Flip.getState._fixed = true;
}

So all you need to do is call that function once and it'll swap in a new Flip.getState() function. 

 

https://stackblitz.com/edit/web-platform-hzf9ib?file=script.js

 

Better? 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...