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

Question: Setting "duration: 0" doesn't work as expected #55

Closed
nltesown opened this issue May 12, 2014 · 8 comments
Closed

Question: Setting "duration: 0" doesn't work as expected #55

nltesown opened this issue May 12, 2014 · 8 comments

Comments

@nltesown
Copy link

It is often useful to jump directly to the final state of an animation and jQuery.animate does just that when you set duration to 0. With velocity, duration: 0 apparently causes the animation to run in the default 400ms duration. A 1ms duration behaves as expected but is not a satisfactory solution when you need an immediate jump to the final state. Thanks!
(PS: your plugin is amazing!)

@julianshapiro
Copy link
Owner

Thanks, @nltesown :)

Supporting a true duration: 0 actually involves a series of hacks to avoid the requestAnimationFrame tick. It would likely be too considerable of a code reorg for me to implement.

However, I can make duration: 0 revert to 1 instead of 400. But, why is 1ms not satisfactory? What is your precise use case, if I may ask? I'd like to get an idea of use cases where someone would want to do this. There are likely more expressive ways to accomplish the same task.

@julianshapiro julianshapiro changed the title Setting duration: 0 doesn't work as expected Question: Setting "duration: 0" doesn't work as expected May 12, 2014
@nltesown
Copy link
Author

Hi Julian,
In my idea of how it should behave (which is the way jQuery.animate behaves, I think), a duration of 0 means that no animation runs at all. For that reason, duration: 1 is not OK because you actually run an animation (and generally get some unwanted flicker). I don't realize at all what it would imply for your code, but I figured it could be possible to simply skip any animation and directly set the final values... As for my use case: I'm translating some overflowing content within a container, and in some situations I need to directly jump from one position to another. I suppose it sounds vague or too specific, and it's true that I can find a workaround anyway... but in fact I was quite surprised when I followed the straightforward idea to set duration: 0 and saw that it didn't work as expected.

@julianshapiro
Copy link
Owner

Have you thought about using forcefeeding to achieve the same jumping effect? If you forcefeed a start value, Velocity will immediately start at that point. No flickering.

http://velocityjs.org/#forcefeeding

If that doesn't solve your issue, I'll look further into implementing a feature like you're describing.

@nltesown
Copy link
Author

Thanks, I had not noticed this advanced setting, I'll have a look.

@TanguyS
Copy link

TanguyS commented May 13, 2014

Actually, my first move was exactly the same (setting duration: 0). Maybe it would be more intuitive?

@julianshapiro
Copy link
Owner

K. I'm going to change 0 to default to 1 instead of 400. This change will be pushed tonight. Thanks, guys.

@TanguyS
Copy link

TanguyS commented May 13, 2014

Thanks a lot Julian!

@julianshapiro
Copy link
Owner

@TanguyS, @nltesown

A duration of 0 now defaults internally to 1ms instead of 400ms.

Update your copies of Velocity.

Thank you!

Rycochet pushed a commit that referenced this issue Aug 3, 2020
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

3 participants