-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
37 lines (32 loc) · 1.53 KB
/
main.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
34
35
36
37
var text = document.querySelector("h1");
var shakes = ["shake", "shake-slow", "shake-hard", "shake-horizontal", "shake-vertical", "shake-rotate", "shake-opacity", "shake-crazy", "shake-chunk"]
function rgbColor() {
var r = Math.floor(Math.random() * 255);
var g = Math.floor(Math.random() * 255);
var b = Math.floor(Math.random() * 255);
return "rgb("+r+", "+g+", "+b+")";
}
setInterval(function () {
var textShadowColor = rgbColor();
var newElements = document.querySelectorAll("h2");
if (newElements) {
newElements.forEach(function (currentElement) {
currentElement.style.color = rgbColor();
currentElement.style.textShadow = "-1px 0 " + textShadowColor +", 0 1px " + textShadowColor +", 1px 0 " +textShadowColor +", 0 -1px " + textShadowColor;
})
}
text.style.color = rgbColor();
text.style.textShadow = "-1px 0 " + textShadowColor +", 0 1px " + textShadowColor +", 1px 0 " +textShadowColor +", 0 -1px " + textShadowColor;
}, 1000)
document.querySelector("body").addEventListener("click", function (e) {
var newElement = document.createElement("h2");
var typeShake = shakes[Math.floor(Math.random() * shakes.length)];
console.log(typeShake)
newElement.style.position = "absolute";
newElement.classList = typeShake + " shake-constant";
newElement.style.margin = "0px";
newElement.style.left = (e.x - 3) + "px";
newElement.style.top = (e.y - 5) + "px";
newElement.innerHTML = "XD";
document.querySelector("body").appendChild(newElement);
});