-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
57 lines (51 loc) · 1.41 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var fist = "images/fistToOne_logo-0.svg"
var one = "images/fistToOne_logo-1.svg"
var colors = ["#5F5EBC", "#8FD9D9", "#F2C948", "#D93B18", "#03A678", "#E47996", "#8C6C9E", "#FF5733", "#8E9FA1"];
var flickCounter = 0;
$('.main__img-fist').on('click', () => {
changeFist();
})
const changeFist = () => {
if ($('.main__img-fist').attr('src') == fist) {
changeColor();
countFlicks();
console.log(flickCounter)
rotateFist();
$('.main__img-fist').attr('src', one)
} else {
changeColor();
$('.main__img-fist').attr('src', fist)
}
}
const changeColor = () => {
if ($('.main__img-fist').attr('src') == fist) {
$('body').css('background-color', getRandomColor())
} else {
$('body').css('background-color', "#FFFFFF")
}
}
const getRandomColor = () => {
let index = Math.floor(Math.random() * colors.length);
return colors[index];
}
const countFlicks = () => {
flickCounter++;
}
const rotateFist = () => {
if (flickCounter % 10 === 0) {
$(".main__img-fist").attr("disabled", "disabled");
$({ degrees: 0 }).animate({ degrees: 360 }, {
duration: 2000,
step: function (now) {
console.log(now)
$('.main__img-fist').css({
transform: 'rotate(' + now + 'deg)'
});
}
})
setTimeout(function() {
console.log("second time stamp", Date.now());
$(".main__img-fist").removeAttr("disabled", "disabled");
}, 2000);
}
}