Jump to content
Search Community

Does GSAP have a tool to make an SVG image track a path?

MariusM 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 code the RED box is tracking the path. I have various SVG images with much more information. So i'm struggling to get these images working into the below path. Does GSAP offer a tool for an SVG to track let's say the below path.

 

<svg width="500" height="300" style="border:2px solid #1eff00;">

    <!-- Line to track -->
    <path id="motionpath1" d="M70,100 C 0,300 300,300 400,200 C 520,70 120,-40 70,100" fill="none" stroke="#001aff"
      stroke-width="2" />
  
    <!-- Object -->
    <path d="M-12,12 h48 v-24 h-48 z" fill="red">
  
      <!-- Assign Object to tracking line -->
      <animateMotion dur="99s" repeatCount="indefinite" rotate="auto">
        <mpath xlink:href="#motionpath1" />
      </animateMotion>
  
    </path>
  
  </svg>

 

Link to comment
Share on other sites

It's best not to mix CSS animations with GSAP as a fight for control can result from that mix. When you use the Morph and Bezier plugins to have an element follow a path, you can quickly set the element to its starting position by using .progress(1).progress(0) before you start the animation.

 

When you're ready to add the amazing MorphSVG plugin (& many more) to your JS arsenal, be sure to check out Club GreenSock.

https://greensock.com/club

 

Happy tweening.

 

  • Like 2
  • Thanks 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...