Jump to content
Search Community

DrawSVG works unexpected

chenxin test
Moderator Tag

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

In this codepen, I have two lines.

 

The animation I want:

initial state: line1 and line2 hidden.

stage one: line1 expand from the center to its ends, and then reverse this animation.

stage two: line2 expand from the center to its ends, and then reverse this animation.

and repeat these two stages infinitely.

 

Now the problem is: at the start of the animation, when line1 is expanding, line2 is already shown.

 

See the Pen QRWVgQ by chenxinnn (@chenxinnn) on CodePen

Link to comment
Share on other sites

This looks like an immediateRender logic thing. By default, immediateRender is true for from() and fromTo() methods. See https://greensock.com/immediateRender 

 

Try just adding immediateRender:false to your second tween of each element: 

const tl = new TimelineMax({repeat: -1});
tl.fromTo(".line1", 1, {drawSVG: "50% 50%"}, {drawSVG: "100%"});
tl.fromTo(".line1", 1, {drawSVG: "100%"}, {drawSVG: "50% 50%", immediateRender:false});
tl.fromTo(".line2", 1, {drawSVG: "50% 50%"}, {drawSVG: "100%"});
tl.fromTo(".line2", 1, {drawSVG: "100%"}, {drawSVG: "50% 50%", immediateRender:false});

 

Or, if you want to simplify your code, you could do this: 

TweenMax.set(".line1, .line2", {drawSVG:"50% 50%"});
const tl = new TimelineMax({repeat: -1});
tl.to(".line1", 1, {drawSVG: "100%", yoyo:true, repeat:1})
  .to(".line2", 1, {drawSVG: "100%", yoyo:true, repeat:1});

 

Does that help? 

  • Like 3
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...