forked from ludovic-esperce/github-page-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
22 lines (18 loc) · 697 Bytes
/
script.js
File metadata and controls
22 lines (18 loc) · 697 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
* Permet de changer dynamiquement la couleur du titre
*/
function changeTitleColor() {
// récupération du titre
const title = document.getElementById('main-title');
// tableau des couleurs possibles
const colors = ['#333', '#e74c3c', '#3498db', '#2ecc71', '#f1c40f'];
// récupération de la couleur actuelle
const currentColor = title.style.color;
// on retrouve une nouvelle couleur au hasard
let newColor = colors[Math.floor(Math.random() * colors.length)];
while (newColor === currentColor) {
newColor = colors[Math.floor(Math.random() * colors.length)];
}
// on applique la nouvelle couleur
title.style.color = newColor;
}