Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Responsive motion path animation example ? #556

Open
littlee opened this issue Mar 10, 2019 · 12 comments
Open

Responsive motion path animation example ? #556

littlee opened this issue Mar 10, 2019 · 12 comments

Comments

@littlee
Copy link

littlee commented Mar 10, 2019

the docs said

Motion path animations are responsive since v3

but the demo in the doc is still a non-responsive version, can someone show me a responsive one ?

@YuriFA
Copy link
Contributor

YuriFA commented Mar 10, 2019

@littlee https://codepen.io/spz/full/zbxqQW - this example with responsive motion path animation (with fix problem #541). The problem is function getParentSvgEl incorrect - it returns an invalid item (parent of svg element, but expected root SVG element ), and then animation function calculate position by viewBox of returned element.

Now you can fix this problem with add viewBox attribute to parent of SVG element.

@mhammo
Copy link

mhammo commented Apr 4, 2019

You'll also have issues if the item you're animating is an SVGElement parented under the same SVG viewBox as your motion path element.

This is because the library attempts to scale the path's x and y at line 637-638 based on the viewBox:
[SVGPoint x] - [viewBox minimum x] * ( [SVG width] / [viewBox width] )

But the viewBox will handle the scaling itself if the animated item is under the same viewBox as your path element. So it gets scaled twice and goes a bit funky: https://codepen.io/anon/pen/EJKaxz

So that's something else to take into account if you're having issues getting the responsive motion path to work.

@merlox
Copy link

merlox commented Jul 16, 2019

Hey bro people seem to ignore this issue so I created a fork and published the fixed version on npm it's called responsive-animejs and the only thing that's changed is the getParentSvgEl to make SVG path animations responsive.

@xeloader
Copy link

You'll also have issues if the item you're animating is an SVGElement parented under the same SVG viewBox as your motion path element.

This is because the library attempts to scale the path's x and y at line 637-638 based on the viewBox:
[SVGPoint x] - [viewBox minimum x] * ( [SVG width] / [viewBox width] )

But the viewBox will handle the scaling itself if the animated item is under the same viewBox as your path element. So it gets scaled twice and goes a bit funky: https://codepen.io/anon/pen/EJKaxz

So that's something else to take into account if you're having issues getting the responsive motion path to work.

I really need this to work. Did anyone get Elements under the same parent SVG to animate with motion paths? It works when the SVG isn't scaled, but when scaling to fit the window everything goes totally bonkers.

I tried responsive-animejs without any luck.

@xeloader
Copy link

xeloader commented Jul 23, 2019

Never mind. In case anyone else has problems with SVGs not following path inside of parent SVG. "Fixed" it by modifying lines 636 - 637 in anime.es.js. Removed svg.w and svg.h which yields

case 'x': return (p.x - svg.x);
case 'y': return (p.y - svg.y);

Thank you @mhammo for valuable information.

I only use animejs to animate svg elements inside of svgs.

@merlox
Copy link

merlox commented Jul 25, 2019

That's interesting because I got it working without removing svg.w and svg.h by just using npm i -S responsive-animejs and importing that. Still, thanks for the information.

@juliangarnier
Copy link
Owner

Should be fixed in v3.1.0!

@benjibee
Copy link

Hey @juliangarnier You mention this being fixed in v3.1.0 but this issue is still open and I believe I'm having the same problem here which I've described here: #605

@SimTheFool
Copy link

I've the same issue with anime v3.1.0. responsive-animejs didn't solve the problem. I would like to try your fix @xeloader.

Never mind. In case anyone else has problems with SVGs not following path inside of parent SVG. "Fixed" it by modifying lines 636 - 637 in anime.es.js. Removed svg.w and svg.h which yields

case 'x': return (p.x - svg.x);
case 'y': return (p.y - svg.y);

Thank you @mhammo for valuable information.

I only use animejs to animate svg elements inside of svgs.

But what's the easiest and/or most elegant way to this ? I wanted to do something like that :

import anime from 'animejs;
anime.getPathProgress = myNewFunction

But getPathProgress doesn't seam to be accessible as an anime entrie. Is there a way to fix it without duplicating/forking the entire library ?

@qqbearqq
Copy link

case 'x': return p.x;
case 'y': return p.y;

ruyuewang added a commit to ruyuewang/anime that referenced this issue Feb 26, 2020
…path

When the svg is scaled by DOM scaling, the path will be scaled twice without this change. This change in function getPathProgress moves away the multiplication of svg dimensions.  When I want to animate obejct along the path(the path is inside a scaled svg), the object will follow the scaled path, which is not what I want. I would like to have the object move along the original path instead of the scaled path.
@adriansuter
Copy link

The fix ruyuewang@a776810 seems to work at least for the mentioned case. Do you, @juliangarnier, have any plans to put that into the official repo?

@jedrzejchalubek
Copy link

jedrzejchalubek commented Jul 23, 2020

Tested out ruyuewang@a776810 fix and I can confirm it fixes the problem in my case too.

It make more sense that scaling is handled by viewBox of SVG and the animated element is hold inside same SVG, so we do not have to think about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests