Whats wrong with this?

N

NeoPhreak

This function is called on the onMouseOut even of a table cell for a menu.
I want it to sort of fade out but for some reason i can't get it to work.
If some one could help me out on this one i would greatly appreciate it.

function out(obj)
{
var colors = new Array(5);
colors[0]='#006666';
colors[1]='#003333';
colors[2]='#002222';
colors[3]='#001111';
colors[4]='';

for(i=0; i<5; i++)
{
setTimeout("return","200");
obj.style.backgroundColor= colors;
}
}

would be called like this:
<td onMouseOut="Out(this);">Something</td>

Thanks in advance.

NeoPhreak >.<
 
L

Lasse Reichstein Nielsen

NeoPhreak said:
This function is called on the onMouseOut even of a table cell for a menu.
I want it to sort of fade out but for some reason i can't get it to work.
If some one could help me out on this one i would greatly appreciate it.
....
setTimeout("return","200");

What is this line supposed to do?
What it actually does is to schedule the execution of the statement
"return" in 200 milliseconds ... which ofcourse does nothing whatsoever.
It doesn't delay execution of the following statements at all (which is
what I guess you wanted it to).
would be called like this:
<td onMouseOut="Out(this);">Something</td>

You function is called "out" with a small "o", but this call is to a
function with a captial "O". Javascript is case sensitive.

Try this:
---
var colors = ["","#011","#022","#033","#066"];
function fade(obj) {
var ctr = colors.length-1;
function fadeStep() {
obj.style.backgroundColor = colors[ctr--];
if (colors<0) {clearInterval(tid);}
}
var tid = setInterval(fadeStep,200);
}
 
D

Douglas Crockford

var colors = new Array(5);
colors[0]='#006666';
colors[1]='#003333';
colors[2]='#002222';
colors[3]='#001111';
colors[4]='';

You should consider using the array literal notation.

var colors = ['#006666', '#003333', '#002222', '#001111', ''];

It is smaller, faster, easier, prettier.

http://www.JSON.org
 

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
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top