...

View Full Version : Changing the words colour



luigicannavaro
03-12-2009, 12:03 PM
Hi friends,

I hope to be able to explain correctly I want (hope) to do.


A little history for you understand I want.


Do you have a web page (.html) with a text placed on it. And in order do you want to see the colour of each word from that text (from the first word to the last) changing its colour (e.g., from blue to red) in sequence. The intervals of time would be 1 second.

So for each 1 second each word from that text will change its colour - from the first to the last word.

It is possible?

Best regards

Luigi

freedom_razor
03-12-2009, 02:09 PM
Yeah, that's possible. [if I understood correctly what you want to do]

Philip M
03-12-2009, 02:43 PM
Mama mia! You certainly ask for some strange things :eek:
Detto fatto. :thumbsup: Il meglio nemico del bel bene. :D



<body onload = "showWords()">

<div id = "mydiv">The quick brown fox jumps over the lazy dog.<br>
The Leith police dismisseth us.</div>

<script type = "text/javascript">

var txt = document.getElementById("mydiv").innerHTML;
var newtext = "";
var txtArray = txt.split(" ");
var len = txtArray.length;
var wdcount = 0;

for (var i = 0; i<txtArray.length; i++) {
txtArray[i] = "<font color = '#0000FF'> " + txtArray[i] + "</font>";
}

newtext = txtArray.join("")
document.getElementById("mydiv").innerHTML = newtext;

function showWords() {
if (wdcount < len) {
for (i=0; i<=wdcount; i++) {
txtArray[i] = txtArray[i].replace(/0000FF/,"FF0000");
}
newtext = txtArray.join("");
document.getElementById("mydiv").innerHTML = newtext;
wdcount ++;
}

else {
window.clearTimeout (tim);
}

tim = setTimeout ("showWords()", 1000);
}

</script>


"I am extraordinarily patient, provided I get my own way in the end".
Margaret Thatcher, in Observer April 4, 1989 British politician (1925 - )

luigicannavaro
03-12-2009, 03:05 PM
Philip,

I know. It is strange, but scientific taxonomy is too strange. My works cover a large range of subjects from the old good times when I was working in Logistics and Transportation.

Could you please fix an issue that the code have at this line?:


var txt = document.getElementById("mydiv").innerHTML;

Best regards

Luigi:thumbsup:

Philip M
03-12-2009, 03:18 PM
Philip,

I know. It is strange, but scientific taxonomy is too strange. My works cover a large range of subjects from the old good times when I was working in Logistics and Transportation.

Could you please fix an issue that the code have at this line?:

Best regards

Luigi:thumbsup:

What I co-incidence! I also worked in Logistics and Transportation, and indeed I ran many senior Logistics Management training courses in Europe, especially Netherlands and Belguim.

But I do not know what issue you refer to. The code works perfectly for me. Please give more information about this "issue".

luigicannavaro
03-12-2009, 03:34 PM
Sorry. I put the script inside the <head></head>.

Now it is working fine.:thumbsup:

Thank you so much

Luigi


**I worked in South America installing and training (personnel for use) Routing Systems in wholesaler firms.

Philip M
03-12-2009, 04:09 PM
OK. The <script> must come in the <body> after the <div>.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum