javascript - calling function from within same function -


i'm converting javascript code jquery , have come halt, heres code...
html:

<div id="text"></div> 

javascript:

keywords = [ "one", "two", "three"] var allowed = true; function changetext ( ) {    if(allowed)    {       var keyword = keywords[ math.floor( math.random() * keywords.length ) ]       document.getelementbyid( "text" ).innerhtml = keyword;    }    settimeout( "changetext()", switchtime ); }  changetext(); 

jquery:

var changeallowed = true; $(document).ready(function changetext() {    if(changeallowed)    {       $("#text").fadeout(500);       var keyword = keywords[ math.floor( math.random() * keywords.length ) ];       $("#text").text(keyword).fadein(1000);    };    settimeout( "changetext()", 2000 ); }); changetext(); 

what should fade text out in new string (which on refresh) every 2 seconds or so, jquery effects working, seems settimeout() or i've not named function properly.

update

my first solution got out of synch when display queue got behind. here updated code uses callbacks timing right, along test fiddle:

var changeallowed = true; var keywords = ["test1", "test2", "test3", "test4", "test5"]; var hide = true;  var toggletextfade = function() {     if(changeallowed) {         var keyword =keywords[math.floor(math.random() * keywords.length)];          $("#text").text(keyword).fadein(1000,null,function(){             $("#text").fadeout(500,null,toggletextfade)});     }                };   $(document).ready(toggletextfade); 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -