Ik heb 3 knoppen, als je op een knop drukt moet deze knop beginnen te flashen...
De tijd is ingesteld op 1 seconde maar toch flasht die veel te snel. Wat doe ik hierbij fout?
[JS]<script language="javascript" type="text/javascript">
var myStyle;
var i = 0;
function flash(obj){
i++;
myStyle = obj.style.background;
if (myStyle == 'rgb(255, 0, 255)'){
obj.style.backgroundColor = '#FF0000';
} else {
obj.style.backgroundColor = '#FF00FF';
}
if (i == 25){
obj.style.backgroundColor = '#FFFFFF';
i = 0;
clearTimeout(timer);
} else {
timer = setTimeout(flash(obj), 1000);
}
}
</script>[/JS]
De tijd is ingesteld op 1 seconde maar toch flasht die veel te snel. Wat doe ik hierbij fout?
[JS]<script language="javascript" type="text/javascript">
var myStyle;
var i = 0;
function flash(obj){
i++;
myStyle = obj.style.background;
if (myStyle == 'rgb(255, 0, 255)'){
obj.style.backgroundColor = '#FF0000';
} else {
obj.style.backgroundColor = '#FF00FF';
}
if (i == 25){
obj.style.backgroundColor = '#FFFFFF';
i = 0;
clearTimeout(timer);
} else {
timer = setTimeout(flash(obj), 1000);
}
}
</script>[/JS]