Forum Moderators: open

Message Too Old, No Replies

recursive function with jQuery

recursive function with jQuery

         

jacosta000

4:13 pm on Mar 17, 2009 (gmt 0)

10+ Year Member



hello!

I'm trying to recursively add information into an element via jquery for the life of the page.

Here is what I'm trying to do:
jQuery(document).ready(function(){
function doMessages(){
jQuery("#message").text("Hello");
jQuery("#message").animate({opacity: 1.0}, 3000);
jQuery("#message").empty();
jQuery("#message").text("We're closed");
jQuery("#message").animate({opacity: 1.0}, 3000);
jQuery("#message").empty();
jQuery("#message").text("Come Back Soon");
jQuery("#message").animate({opacity: 1.0}, 3000);
jQuery("#message").empty();
setTimeout( "doMessages();", 5000 );
}

});

I'm sure there's an easier way to do this. And I'm also sure there's a way to get this to actually work. Unfortunately, I haven't gotten anywhere. Anyone have any ideas?

daveVk

12:05 am on Mar 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This thread may have clues [webmasterworld.com...] assuming animate also has callback parameter

jacosta000

12:40 pm on Mar 18, 2009 (gmt 0)

10+ Year Member



that is exactly what I was looking for.

Thanks!

jacosta000

9:01 pm on Mar 18, 2009 (gmt 0)

10+ Year Member



Now that I have something that works, is there a more efficient way to do this:

var $j = jQuery.noConflict();
function doMessages() {
$j('#message').fadeIn(3000);
$j('#message').html("This is message number 1 and it has a <a href='http://www.google.com'>link</a>");
$j('#message').fadeOut(3000, function () {
$j('#message').html("This is the second message");
$j('#message').fadeIn(3000);
$j('#message').fadeOut(3000, function () {
$j('#message').html("Message number 3 is right here");
$j('#message').fadeIn(3000);
$j('#message').fadeOut(3000, function () {
$j('#message').html("This right here is message number 4");
$j('#message').fadeIn(3000);
$j('#message').fadeOut(3000, function () {
$j('#message').html("Hello, this is message number 5");
$j('#message').fadeIn(3000);
$j('#message').fadeOut(3000, function () {
setTimeout('doMessages();', 500);
});
});
});
});
});
}

$j(document).ready(function() {
doMessages();
});

Thanks!

daveVk

12:38 am on Mar 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Possibly something like following

var msgs = [ ... ];
var msgNo=1;
function doMessages() {
if ( msgNo>msgs.length ) {msgNo=0;}
$j('#message').html(msgs[msgNo++]);
$j('#message').fadeIn(3000);
$j('#message').fadeOut(3000, function () {
setTimeout('doMessages();', 500);
});
)

jacosta000

12:48 pm on Mar 19, 2009 (gmt 0)

10+ Year Member



that is awesome. Thank you so much!