Re: (AngularJS UnderscoreJS) loop through array and assign value to variable with delay?

Friday, March 15, 2013

The page below does what you asked, only at the rate of 500 millisecs per array element instead of 100, and instead of a simple variable, the values from the array are assigned to the style color property.

Good luck...

----Begin HTML Doc----
<html>

<head>
<title>Assign Values From Array Example</title>
</head>
<body>
<div id='OUT'><big><b>Watch me change colors...</b></big></div>
<script>


// Convenience function
function Gid(id) {
    return document.getElementById(id);
}

// Number of millisecs to hold color...
var Msecs = 500; 

// Array of colors to use...
var Arr = ["blue","green","red","black","orange"];

// Index of next array element to use
var Ind = 0;


// Operation to perform every Msecs
function OnTimeout() {
    // Assign color from array
    Gid("OUT").style.color = Arr [Ind];
    // Advance to next color in array
    // and then recycle to beginning...
    Ind = (Ind + 1) % Arr.length;
    // Call OnTimeout() again in Msecs milliseconds...
    window.setTimeout("OnTimeout()", Msecs);
}


// Start the process
OnTimeout();

</script>
</body>
</html>
----Begin HTML Doc----


On Thursday, March 14, 2013 2:51:00 PM UTC-4, yahya Kacem wrote:
Hi everyone, I need to loop through an array and assign each value to the same variable with delay of 100ms I'm using underscore.js for this here's a example plunker.
Thanks in advance.

--
You received this message because you are subscribed to the Google Groups "JavaScript Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javascript-information+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Copyright © 2010 Web Design | Free Blogger Templates by Splashy Templates | Layout by Atomic Website Templates

Vida de bombeiro Recipes Informatica Humor Jokes Mensagens Curiosity Saude Video Games Animals Diario das Mensagens Eletronica Rei Jesus News Noticias da TV Artesanato Esportes Noticias Atuais Games Pets Career Religion Recreation Business Education Autos Academics Style Television Programming Motosport Humor News The Games Home Downs World News Internet Design Entertaimment Celebrities 1001 Games Doctor Pets Net Downs World Enter Jesus Mensagensr Android Rub Letras Dialogue cosmetics Genexus lasofia thebushrajr wingshock tripedes gorduravegetal dainfamia dejavu-transpersonal jsbenfica republicadasbadanas ruiherbon iranianforaryans eaystcheyl fotosdanadir Só Humor Curiosity Gifs Medical Female American Health Madeira Designer PPS Divertidas Estate Travel Estate Writing Computer Matilde Ocultos Matilde futebolcomnoticias girassol lettheworldturn topdigitalnet Bem amado enjohnny produceideas foodasticos cronicasdoimaginario downloadsdegraca compactandoletras newcuriosidades blogdoarmario arrozinhoii