julianshapiro / velocity

Accelerated JavaScript animation.
VelocityJS.org
MIT License
17.29k stars 1.56k forks source link

[Feature request] Options as callbacks #789

Open AdamSGit opened 7 years ago

AdamSGit commented 7 years ago

In the same way you can pass properties as callbacks (eg :) $('.els).velocity({ left: function(index, length) {} });, it would be nice to have the possibilitie to do it with options as well (delay, duration...)

A concrete case : I need to move several elements to the same position, but leaving a "trail" doing it. For that, you add a bit more duration on each element. To achieve that, you have, for now, to loop into your elements and apply velocity on each, which is a complete waste of performances.

It would be great to do $('.els').velocity({ left: 600, top: 200 }, { duration: function(index,length) { return 600 + i * 40 } })

Pointy commented 6 years ago

Note that in modern JavaScript you can do that by writing getter functions for the properties.

Rycochet commented 6 years ago

@Pointy the problem with that is it won't necessarily give the options people expect - some have to be per-animation, some are per-element, and at least one is global only - so specific code and documentation will say what is and isn't supported.

Saying that - really good point ;-)

Rycochet commented 6 years ago

I've started adding this with the stagger option - more will come over time (just need to ensure they're working properly for each one).