Jump to content
Search Community

yPercent on SVG path

Noetik
Moderator Tag

Go to solution Solved by mvaneijgen,

Recommended Posts

Posted

Hello,
I am trying to animate yPercent on a SVG element but doesn't seem to work. Checked the console and doesn't seem to change anything.

xPercent (if uncomment it) works fine. Could you explain why in order to make the lines animate vertically?

See the Pen KwKVjXZ by Manolis-Tsalampounis (@Manolis-Tsalampounis) on CodePen.

  • Solution
mvaneijgen
Posted

That is probably due to the fact that a line has no height and you're trying to move the element 100% of 0, which is 0 and also 50% of 0 = 0, so there is no movement. 

 

You can how ever set y and just animate a pixel value that suites you. In the process of debugging this I'd removed some of your code and changed it to how I would set it up. By the way have you seen our helper functions https://gsap.com/docs/v3/GSAP/gsap.utils/ there is a random function build in to GSAP! Also instead of targeting each line, you can target them all at the same time and just set repeat: -1 and repeatRefresh: true,  to have to change the values each time. 

 

Hope it helps and happy tweening! 

 

See the Pen OPJMeKx?editors=0011 by mvaneijgen (@mvaneijgen) on CodePen.

 

  • Like 3
Posted

Hi,

 

Just to complement what @mvaneijgen already mentioned you can inspect the line elements using the getBBox() method:

https://developer.mozilla.org/en-US/docs/Web/API/SVGGraphicsElement/getBBox

 

For every line you'll basically get this:

SVGRect {x: 0, y: 0, width: 2436.89990234375, height: 0}

Also you can check the Attributes Plugin in order to tween the x and y attributes of the line elements:

https://developer.mozilla.org/en-US/docs/Web/SVG/Element/line

 

But probably tweening the transform of the lines is enough as Mitchel's demo already shows.

 

Happy Tweening!

  • Like 2
Posted

Very helpful, thank you!

  • Like 1

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