Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/267955-jquery-question/
Share on other sites

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 ().

Link to comment
https://forums.phpfreaks.com/topic/267955-jquery-question/#findComment-1374923
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/267955-jquery-question/#findComment-1374927
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/267955-jquery-question/#findComment-1375153
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/267955-jquery-question/#findComment-1375294
Share on other sites

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).

Link to comment
https://forums.phpfreaks.com/topic/267955-jquery-question/#findComment-1375297
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/267955-jquery-question/#findComment-1375310
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.