JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 25th, 2012, 08:32 PM
richpri's Avatar
richpri richpri is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Location: Chicago
Posts: 49 richpri User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 27 m 23 sec
Reputation Power: 1
Facebook
Question jQuery - How to interrupt a queue?

I have a situation where a web application has to display a message
for 30 seconds. I could use something like this:

Code:
$('#lognote').text(startMessage).delay(30000).text("");


But the application may have to display another message before the
30 seconds has elapsed. How can I interrupt the queue to cause the
new message to display before the 30 seconds has elapsed?

Reply With Quote
  #2  
Old December 25th, 2012, 10:21 PM
web_loone08's Avatar
web_loone08 web_loone08 is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2008
Posts: 599 web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 12 h 40 m
Reputation Power: 69
You could do something like this, because the delay() does not seem to work, as you desire it to; when tested:

Code:
<script src="http://code.jquery.com/jquery-latest.js"></script>

<div id="lognote"></div>

<script>
var startMessage="Hello";
var interuptMessage="Goodbye =(";
$('#lognote').text(startMessage);
setTimeout(function() {
$('#lognote').text(interuptMessage);
},"5000");
setTimeout(function() {
$('#lognote').text(startMessage+" Again!");
},"15000");
</script>
Comments on this post
richpri agrees: Thanks a lot!

Reply With Quote
  #3  
Old December 26th, 2012, 11:24 AM
richpri's Avatar
richpri richpri is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Location: Chicago
Posts: 49 richpri User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 27 m 23 sec
Reputation Power: 1
Facebook
Lightbulb

Thank you web_loone08 for showing me the setTimeout() function. I was able to use it [along with the clearTimeout() function] to create a function that does exactly what I wanted. This is the tested version of this function.

javascript Code:
Original - javascript Code
  1. var BD18 = {};
  2. BD18.noteTimeout = null;
  3.  
  4. /* Function doLogNote displays a lognote for 30 seconds.
  5. * A new lognote will replace any previous log note
  6. * that has not yet timed out. BD18.noteTimeout is a
  7. * global variable with an initial value of null.
  8. */
  9. function doLogNote(note) {
  10.   if(BD18.noteTimeout != null) {
  11.     clearTimeout(BD18.noteTimeout);
  12.   }
  13.   $('#lognote').text(note);
  14.   BD18.noteTimeout = setTimeout(function() {
  15.     $('#lognote').text("");
  16.     BD18.noteTimeout = null;
  17.   },"20000");
  18. }

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > jQuery - How to interrupt a queue?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap