Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#11672 closed bug (plugin)

delay(0) still delays

Reported by: torsten@… Owned by: torsten@…
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?

Change History (4)

comment:1 Changed 7 years ago by dmethvin

Owner: set to torsten@…
Status: newpending

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?

comment:2 in reply to:  1 Changed 7 years ago by torsten@…

Status: pendingnew

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

comment:3 Changed 7 years ago by gibson042

Resolution: plugin
Status: newclosed

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

comment:4 Changed 7 years ago by anonymous

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.

Note: See TracTickets for help on using tickets.