-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
34 lines (29 loc) · 996 Bytes
/
script.js
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
var links = document.querySelectorAll("a");
var colors = ["#7200F5", "#0065FF", "#00F5BE", "#99FF00", "#F50043"];
var pageTitle = document.querySelector('h1 a');
var currentTitle = pageTitle.innerHTML;
var domTitle = document.title;
var clickedColor = '';
pageTitle.innerHTML = currentTitle + ':' + domTitle;
for (var l = 0; l < links.length; l++) {
(function(l) {
links[l].addEventListener("mouseenter", function() {
changeColor(links[l]);
});
links[l].addEventListener("mouseleave", function() {
resetColor(links[l]);
});
if (domTitle = links[l].innerHTML) {
links[l].style.color = clickedColor;
}
})(l);
}
function changeColor(element) {
var colorsLength = colors.length;
var colorIndex = Math.floor(Math.random() * colorsLength);
element.style.color = colors[colorIndex];
clickedColor = colors[colorIndex];
}
function resetColor(element) {
element.style.color = "#000000";
}