1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| var coloration = [255,255,255];
// cette fct fonctionne bien...
function double(coloration){
doubleValeur.addEventListener('click', function (evt){
var small = parseInt(valeurSmall.innerHTML);
var big = parseInt(valeurBig.innerHTML);
coloration = darker(coloration);
console.log(coloration);
if (small === 400 && big === 800){
small = 500;
big = 1000;
} else {
small = small * 2;
big = big * 2;
}
valeurSmall.innerHTML = small.toString();
valeurBig.innerHTML = big.toString();
valeurSmall.style.color = "rgb("+coloration[0]+","+coloration[1]+","+coloration[2]+")";
valeurBig.style.color =
"rgb("+coloration[0]+","+coloration[1]+","+coloration[2]+")";
if (resetValeur.getAttribute("class") === "disabled"){
resetValeur.setAttribute("class", "");
}
});
}
// voici ma fonctionne : et aussi marche bien
function darker(coloration){
if (coloration[1] > 0 && (coloration[1] - 25 >= 0) ){
coloration[1] = coloration[1] - 25;
coloration[2] = coloration[2] - 25;
} else if (coloration[0] > 0 && (coloration[0] - 25 >= 0) ) {
coloration[0] = coloration[0] - 25;
coloration[1] = 0;
coloration[2] = 0;
} else {
coloration[0] = coloration[1] = coloration[2] = 0;
}
return coloration;
}
// Il est ici le problème....
function reset(coloration){
resetValeur.addEventListener('click', function (evt){
var small = parseInt(valeurSmall.innerHTML);
var big = parseInt(valeurBig.innerHTML);
console.log(coloration);
coloration = lighter(coloration);
console.log(coloration);
small = 25;
big = 50;
valeurSmall.innerHTML = small.toString();
valeurBig.innerHTML = big.toString();
resetValeur.setAttribute("class", "disabled");
// ces valeurs remettre effectivement mon texte en blanc....
valeurSmall.style.color = "rgb(255,255,255)";
valeurBig.style.color = "rgb(255,255,255)";
return coloration; // ca ne marche pas
});
}
// cette fct sera caller dans reset seulement, un genre de remise à valeur initiale
function lighter(coloration){
coloration = [255,255,255];
return coloration;
}
Voici mes appels de fonctions tel qu'on me le enseigner à l'école :
document.addEventListener('DOMContentLoaded', function(event) {
double(coloration);
reset(coloration);
}); |
Partager