Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 9 years ago

#8489 closed enhancement (wontfix)

Add a 'complete' parameter to .delay() for using callbacks. That was it's super simple to delay custom, non-jQuery functions.

Reported by: trusktr Owned by:
Priority: undecided Milestone: 1.next
Component: queue Version: 1.5.1
Keywords: Cc:
Blocked by: Blocking:


For example, it'd be super nifty to do this:

$(this).delay(5000, function() {

The above would have the effect of executing non_jquery_function() after waiting 5 seconds when .delay() is added to the object's queue.

This would be super convenient!

Is there already a way to do this?

Change History (6)

comment:1 Changed 10 years ago by trusktr

I guess

$(this).delay(5000).queue( function(next){


Is the way to do it. However, it'd still be convenient to just use a callback within .delay().

Version 1, edited 10 years ago by trusktr (previous) (next) (diff)

comment:2 Changed 10 years ago by trusktr

Last edited 10 years ago by trusktr (previous) (diff)

comment:3 Changed 10 years ago by ajpiano

Component: unfiledqueue

As it says on the docs for .delay()

"The .delay() method is best for delaying between queued jQuery effects. Because it is limited—it doesn't, for example, offer a way to cancel the delay—.delay() is not a replacement for JavaScript's native setTimeout function, which may be more appropriate for certain use cases."

I can't see why we'd add this parameter - I understand why one might think it convenient, but it's really just a super thin layer around setTimeout that obscures users from actually writing basic JavaScript. On the other hand, there might be a valid use case here, so I'm going to throw this into the feature proposals for 1.6 so we can get more opinions on this and we can evaluate based on whatever consensus is generated there.

comment:4 Changed 10 years ago by scottgonzalez

I think the use case provided is a bit silly, but I think there are valid use cases and I would've expected this to work. I could see users wanting to do:

$( el )
    .animate( ..., fn1 )
    .delay( duration, fn2 )
    .animate( ..., fn3 );

comment:5 Changed 10 years ago by trusktr

I agree scott.gonzales: my example was very simple for the sole purpose of showing how it'd work. Of course, in a more realistic situation, you'd be calling .delay() amidst a chain of multiple jQuery animations where in the middle of this chain you might need to call a function that has no duration time associated with it but wherein you would still need a padding of time around that said function. This would come in handy when you want to pad .css(), .remove(), .append(), or any other durationless methods/functions with time.

ajpiano, I'm guessing that using .delay() incorporates javascript's native setTimeout() somewhere in the source code, right?

I guess the feature I'm asking for would do nothing more than the exact same thing you are doing when you use .queue() and .dequeue() like in my example above. It would be identical to the functionality of jQuery animations that use a "complete" parameter to launch functions only after animations are complete. In the case of .delay(), the animation is an animation-less animation that acts on nothing, but it still has a duration.

All in all, it'd be a simple way to type a few less characters, while maintaining the same exact functionality as animated methods that wait the duration of their respective animations to execute the next function.

Taking into account the time it took to type this reply, and if this feature request (enhancement) gets approved, then it'd be cool to know my time spent on this would save thousands of developers a few seconds each time they need to queue custom functions with a time delay, which would happen most often when they need to compensate for previous animations where the duration of said animations are known in order to execute functions that don't normally queue themselves to the queue.

Last edited 10 years ago by trusktr (previous) (diff)

comment:6 Changed 10 years ago by ajpiano

Resolution: wontfix
Status: newclosed

We looked at this proposal for 1.6, but the consensus was against landing this. We appreciate the time you took to put this together, but it introduces complexity and obscures around the fact that sometimes, using native JavaScript methods (setTimeout) or a plugin (like doTimeout is a better solution than us adding functionality directly to jQuery core.

(FYI, delay does use setTimeout internally.)

Note: See TracTickets for help on using tickets.