M.O.S. Studios Posted September 3, 2012 Share Posted September 3, 2012 I'm making a script that updates a number in a div every 5 seconds. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title></title> <script src='jquery.js'></script> <script> $(document).ready(function(){ $.fn.counter = function(fc){ var obj = $(this); var animationSeq = new Array(); var retFun = function(i){ $(obj).text(i); } var retFun_func = function(i){ return function(){retFun(i)}; } for(var i = 0; i<=fc; i++){ animationSeq[i] = retFun_func(i); } for(x in animationSeq){ $(obj) .queue('bf', function(next){ animationSeq[x](); }); } $(obj).dequeue('bf'); } $('#t').counter('25'); }); </script> </head> <body> <div id='t'></div> </body> </html> I'm trying to add a 5 second between each number change. How do I incorporate the .delay function?? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/267955-jquery-question/ Share on other sites More sharing options...
Spring Posted September 3, 2012 Share Posted September 3, 2012 I believe you're looking for The setInterval() Method. http://www.w3schools.com/js/js_timing.asp Quote Link to comment https://forums.phpfreaks.com/topic/267955-jquery-question/#findComment-1374913 Share on other sites More sharing options...
M.O.S. Studios Posted September 3, 2012 Author Share Posted September 3, 2012 I want to use delay(). this I posted a striped down version of the script, But I want to place things into a queue and figure out how to delay triggering each event. Quote Link to comment https://forums.phpfreaks.com/topic/267955-jquery-question/#findComment-1374916 Share on other sites More sharing options...
Christian F. Posted September 3, 2012 Share Posted September 3, 2012 It doesn't matter what you want to use, if said function doesn't provide you with the correct functionality. So don't focus on what you want to use, but what you need to use in order to get the wanted result. For updating something every # seconds you're looking at setInterval (). Quote Link to comment https://forums.phpfreaks.com/topic/267955-jquery-question/#findComment-1374923 Share on other sites More sharing options...
M.O.S. Studios Posted September 3, 2012 Author Share Posted September 3, 2012 Arg, setInterval is only for triggering the same function. That is not what I'm asking. Hurry has a built in way of queuing different functions and adding a delay between each one. The trick to doing why u want is going tO be delay. Because later on I am going to ad other functions into the queue. So setInterval is not what I need Quote Link to comment https://forums.phpfreaks.com/topic/267955-jquery-question/#findComment-1374927 Share on other sites More sharing options...
Spring Posted September 3, 2012 Share Posted September 3, 2012 and appending .delay isn't working? Quote Link to comment https://forums.phpfreaks.com/topic/267955-jquery-question/#findComment-1374940 Share on other sites More sharing options...
M.O.S. Studios Posted September 4, 2012 Author Share Posted September 4, 2012 Nope tried everything, No matter where I add the .delay() I have the same problem. All the functions in the queue trigger at the same time. How do I add the pause in between them! Quote Link to comment https://forums.phpfreaks.com/topic/267955-jquery-question/#findComment-1374991 Share on other sites More sharing options...
codefossa Posted September 4, 2012 Share Posted September 4, 2012 For a one second delay: $.delay(1000, functionName()); Wouldn't it make more sense to just use setTimeout though? Quote Link to comment https://forums.phpfreaks.com/topic/267955-jquery-question/#findComment-1375115 Share on other sites More sharing options...
Adam Posted September 4, 2012 Share Posted September 4, 2012 I don't understand how you're trying to use delay() and queue() together, they are very different in what they do. The code you posted didn't include any usage of delay() either. Could you explain a little more what you're trying to achieve please? Quote Link to comment https://forums.phpfreaks.com/topic/267955-jquery-question/#findComment-1375153 Share on other sites More sharing options...
M.O.S. Studios Posted September 4, 2012 Author Share Posted September 4, 2012 OK here is what I have. Queue bf Function 1 Function 2 Function 3 Function 4 Function 5 I want to be able to use delay to beable to set how much time is between each function. according to the jquery website .delay() should be able to do that. Don't know why it isn't. If I use SetTimeout(), I will need the clients computer to start calculating 25 different functions instead of 1 queue... isn't the best way to do it. Quote Link to comment https://forums.phpfreaks.com/topic/267955-jquery-question/#findComment-1375294 Share on other sites More sharing options...
codefossa Posted September 4, 2012 Share Posted September 4, 2012 With .delay() they're gonna have to do it too. Is there a set interval between these, or is it different for each one? If it's the same, and you just want to do one after another, that wouldn't be hard. If they're different, then you can go about it a few ways, but I still wouldn't use delay (I don't think .. off the top of my head). Quote Link to comment https://forums.phpfreaks.com/topic/267955-jquery-question/#findComment-1375297 Share on other sites More sharing options...
M.O.S. Studios Posted September 4, 2012 Author Share Posted September 4, 2012 each function is different iteration of the same function. I've already go them set up in a custom queue. I just want to set the queue to space out triggering the functions. Quote Link to comment https://forums.phpfreaks.com/topic/267955-jquery-question/#findComment-1375299 Share on other sites More sharing options...
codefossa Posted September 5, 2012 Share Posted September 5, 2012 Well, from what I can understand, this might be what you want? http://xaotique.no-ip.org/tmp/5.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Temporary Page</title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { var funcs = [greet, wave, leave]; function greet() { $("body:eq(0)").append("Hi, welcome to the site." + "<br />"); } function wave() { $("body:eq(0)").append("Now I wave hello." + "<br />"); } function leave() { $("body:eq(0)").append("Bye now." + "<br />"); } var i = 0, inter = setInterval(function() { if (funcs[i] != undefined) { funcs[i](); i++; } else { clearInterval(inter); } }, 1000); }); </script> </head> <body> Stuff goes in here.<br /><br /> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/267955-jquery-question/#findComment-1375310 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.