working with time?

B

Bad_Kid

how to set javascript to start every x ms?? [setTimeout('name()', speed)] ??
- and how to start that same javascript (second instance) with delay - for
example ->
javascript colors specified text to red and back to black every x ms...
how to start that same javascript on another text, with slight delay? (so it
goes: 1st text goes red, __ , 2nd text goes red, ___ 1st text goes black,
___ 2nd text goes black,___ ???
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
function changeText (id) {
var element = document.getElementById("text" + id);
stuff = false;
if (document.all) {
if (element.style.color == "rgb(255, 0, 0)") {
element.style.color = "#000000";
} else {
element.style.color = "#FF0000";
}
} else {
if (element.style.color == "#FF0000") {
element.style.color = "#000000";
} else {
element.style.color = "#FF0000";
}

if those 5 lines work,
element.style.color ^= 0xFF0000
should work

However, since the colour is being changed in a preordained sequence, it
should be simpler to use
X %= n ; element.style.color = [0x000000, 0xFF0000, ...][X++] ;
where the literal array has n elements and X is declared outside the
function changeText. That may well remove the need for feature
detection.


Code should be indented to show logical structure - see FAQ/notes.
 
L

Lasse Reichstein Nielsen

Dr John Stockton said:
if those 5 lines work,
element.style.color ^= 0xFF0000
should work

Unlikely. The value of element.style.color is a string.
You don't know the format returned, althoug it is likely to be
#xxxxxx. Converted to a number, that is NaN, and xor'in it with
0xFF0000 will not change that ... and if it did, the result would
be a number, not a CSS color value.

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top