Bug Tracker

Ticket #6255 (closed feature: worksforme)

Opened 4 years ago

Last modified 4 years ago

.delay() is not stopped by .stop(true,true)

Reported by: ffx Owned by:
Priority: undecided Milestone: 1.4.3
Component: effects Version: 1.4.2
Keywords: delay stop Cc:
Blocking: Blocked by:

Description

.delay() is implemented with a setTimeout() without remembering the return value. So the timeout cannot be stopped once started.

Could you implement it in one of these ways:

  1. The user can manually remove the timeout with clearTimeout()
  1. Nicer would be, if .delay would be also stopped by .stop() / .clearQueue()

Change History

comment:1 Changed 4 years ago by addyosmani

  • Priority set to undecided
  • Status changed from new to closed
  • Resolution set to worksforme

Please note that in reference to .delay():

(from our documentation)

jQuery.delay() is best for delaying between queued jQuery effects and such, and is not a replacement for JavaScript's native setTimeout function, which may be more appropriate for certain use cases.

In the above case if you were to require access to the complete setTimeout() function with a callback it would make more sense to use that rather than .delay() however..

.delay() *can* actually already be stopped using clearQueue as follows:

$("#element").delay(800).fadeOut(400); $("#element").clearQueue();

You can see this working below:

Live test:  http://jsfiddle.net/k4853/

If you have further comments or would like to submit a further explanation as to the benefits of allowing .stop() to be used here (as well as how it would behave) please feel free to submit a new ticket.

comment:2 follow-up: ↓ 3 Changed 4 years ago by JurekRaben

addyosmani: Sorry, that's not true!

See this extended example:  http://jsfiddle.net/k4853/9/

clearQueue() just clears the queue instructions but NOT the setTimeout. So next usage of delay will then cause wrong behaviour and wrong results.

This has to be fixed. I already did this with a patch for the jquery core, but maybe it needs some review and improvements.  jquery delay patch

comment:3 in reply to: ↑ 2 Changed 4 years ago by anonymous

See this bug report here: http://bugs.jquery.com/ticket/6576

Note: See TracTickets for help on using tickets.