0
Simon says
I need to make this cool game using pure javascript (no jQuary). I have a problem make the button's opacity change and go back to normal. I have tried to change it using setTimeout but Its stuck on the new opacity I gave. Thanks alot!
3 Réponses
+ 9
create variable with a value of 0
use setInterval(function, 1000) to invoke a function which will add 1 to your var
if var is greater than 0 you give the button the new opacity
if var is greater than 2 give the button the old opacity, use clearInterval and set the var back to 0
0
How I can see your code in order to help?
0
Ok I found this code:
function showMoves() {
var i = 0;
var moves = setInterval(function(){
playGame(r_array[i]);
i++;
if (i >=r_array.length) {
clearInterval(moves);
}
}, 600)
}
function playGame(field) {
document.getElementById(field).style.opacity="0.3";
setTimeout(function(){
document.getElementById(field).style.opacity="1";
}, 1000);
}
It works just fine but still I don't understand 100% why this one is good.