#6255 closed feature (worksforme)
.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: | |
Blocked by: | Blocking: |
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:
- The user can manually remove the timeout with clearTimeout()
- Nicer would be, if .delay would be also stopped by .stop() / .clearQueue()
Change History (3)
comment:1 Changed 12 years ago by
Priority: | → undecided |
---|---|
Resolution: | → worksforme |
Status: | new → closed |
comment:2 follow-up: 3 Changed 12 years ago by
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
Note: See
TracTickets for help on using
tickets.
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.