Side navigation
#11672 closed bug (plugin)
Opened April 28, 2012 08:26PM UTC
Closed April 29, 2012 01:12PM UTC
Last modified April 29, 2012 05:02PM UTC
delay(0) still delays
Reported by: | torsten@allthingswordpress.de | Owned by: | torsten@allthingswordpress.de |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.7.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
I'm trying to use a configurable delay value to control the elasticity of animating an element of top of another:
var elasticity = 25; // how long the animation of the second element should be delayed to create the rubber band effect $('.slide_background').animate({ 'top': '+=50px' }); $('.slide_content_element').delay(elasticity).animate({ 'top': '+=50px' });
The idea is to be able to configure the above snippet to be elastic or concrete depending on the value of 'elasticity'. Supposedly, a value of 0 should result in absolutely no delay. That is
var elasticity = 0; $('.slide_background').animate({ 'top': '+=50px' }); $('.slide_content_element').delay(elasticity).animate({ 'top': '+=50px' });
should be the same like starting the second animation without any delay:
$('.slide_background').animate({ 'top': '+=50px' }); $('.slide_content_element').animate({ 'top': '+=50px' });
But still, even with a value of 0, delay() adds a visible delay. Any ideas?
Attachments (0)
Change History (4)
Changed April 29, 2012 12:06AM UTC by comment:1
owner: | → torsten@allthingswordpress.de |
---|---|
status: | new → pending |
Changed April 29, 2012 09:36AM UTC by comment:2
status: | pending → new |
---|
Replying to [comment:1 dmethvin]:
> Supposedly, a value of 0 should result in absolutely no delay. Why? That certainly isn't the case with setTimeout(fn, 0)
which waits a dozen or more milliseconds on most browsers. So it kind of makes sense. https://github.com/jquery/jquery/blob/1.7.2/src/queue.js#L136 Can you provide a test case on jsFiddle.net?
Yes, jsFiddle example see http://jsfiddle.net/AhSRh/12/
As for "supposedly .delay(0)" should make for no delay: I'm somewhat new to javascript/jQuery, but per common sense a "delay of zero milliseconds" should be no delay at all (or not noticable). After all, the value determines how many milliseconds the delay should be - and if delay(1000) produces a delay of 1000 milliseconds, delay(10) should produce a delay of 10 milliseconds and delay(0) therefore a delay of 0 milliseconds - that is no visible delay.
I'm not sure how setTimeout handles this, but from common sense, I figured I'd be able to make the delay diminish when setting its duration to 0. Even if it's still listed in the queue.
Changed April 29, 2012 01:12PM UTC by comment:3
resolution: | → plugin |
---|---|
status: | new → closed |
You have misunderstood; delay(0)
means the same thing as setTimeout(fn, 0)
: wait for ''at least'' 0 milliseconds before executing. I think that what you want is a simple plugin along the lines of jQuery.fn.maybeDelay = function( time, type ) { return time ? this.delay.apply( this, arguments ) : this; };
.
Changed April 29, 2012 05:02PM UTC by comment:4
Works like a charm, thank you very much for taking the time to sort this out. I think a note in the official documentation for the function that delay(0) !== no delay would be helpful should anyone else ever stumble about this issue.
Why? That certainly isn't the case with
setTimeout(fn, 0)
which waits a dozen or more milliseconds on most browsers. So it kind of makes sense.https://github.com/jquery/jquery/blob/1.7.2/src/queue.js#L136
Can you provide a test case on jsFiddle.net?