Jump to content
Search Community

MorphSVG plugin

atomboy test
Moderator Tag

Go to solution Solved by PointC,

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

I have a button which morphs an svg on click. However when clicking rapidly the svg path is malformed. How to avoid this?

 

Edit: Seems to go away when I remove transform-origin so the problem lies within transform origin

 

this.tl.to(this.envTop, 0.5, { morphSVG: this.envTopPath, rotation: 0, transformOrigin: '50% 50%' }, 0)
                .to(this.envBottom, 0.5, { morphSVG: this.envBottomPath, rotation: 0, transformOrigin: '50% 50%' }, '-=0.5')


this.tl.to(this.envTop, 0.5, { morphSVG: this.envTopPath, rotation: 0 }, 0)
                .to(this.envBottom, 0.5, { morphSVG: this.envBottomPath, rotation: 0 }, '-=0.5')
Link to comment
Share on other sites

I'ts the rotation this is the code I use each click the timeline reinstantiate. If essential I could make a pen to reproduce

 

        const tl = new TimelineLite()
        tl.set(this.envTop, { transformOrigin: '50% 50%' })
            .set(this.envBottom, { transformOrigin: '50% 50%' })
        if (!checkedTwo && two) {
            tl.to(this.envTop, 0.5, { morphSVG: this.crossTopPath, rotation: 360 }, 0)
                .to(this.envBottom, 0.5, { morphSVG: this.crossBottomPath, rotation: 360 }, '-=0.5')
                .to(this.envLeft, 0.5, { x: -300 }, '-=0.5')
                .to(this.envRight, 0.5, { x: 300 }, '-=0.5')
        } else if (checkedTwo) {
            tl.to(this.envTop, 0.5, { morphSVG: this.envTopPath, rotation: 0 }, 0)
                .to(this.envBottom, 0.5, { morphSVG: this.envBottomPath, rotation: 0 }, '-=0.5')
                .to(this.envLeft, 0.5, { x: 0 }, '-=0.5')
                .to(this.envRight, 0.5, { x: 0 }, '-=0.5')
        }

 

 

I also did a play reverse without reinstatiating the timeline but that also gave wrong positioning after clicking fastly on the button.

Link to comment
Share on other sites

  • Solution

Hi atomboy :)

 

When something is looking odd or getting out of position with rapid clicks that tells me tweens are getting overwritten. For click morphs I always create a timeline and play/reverse it on click rather than creating new tweens or timelines on each click.

 

As Jack mentioned, a CodePen demo is always better so we can edit your code and give you the best help. Please let us know when you have that ready.

 

Thanks.

  • Like 3
Link to comment
Share on other sites

I'm using React. The way I setup the timeline to make things work well is to instantiate the timeline in the constructor() { ... } and to add the animation in componentDidMount() { ... } -- Then play reverse it in the click handler. 

Thanks for the support, great as always!

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...