-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
77 lines (63 loc) · 2.17 KB
/
app.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const ratings = document.querySelectorAll('.btn-container input');
let rate;
ratings.forEach(rating => {
// hover elements bg & clr
hoverElement(rating);
if(rating.value == localStorage.getItem('rate')) {
rating.style.backgroundColor = 'rgb(149, 158, 172)';
rating.style.color = 'rgb(255, 255, 255)';
activeElement(rating);
};
rating.addEventListener('click', () => {
ratings.forEach(item => {
if(rating !== item) {
// default elements bg & clr
item.style.backgroundColor = 'rgba(149, 158, 172, 0.2)';
item.style.color = 'rgb(149, 158, 172)';
hoverElement(item);
};
// active element bg & clr
rating.style.backgroundColor = 'rgb(149, 158, 172)';
rating.style.color = 'rgb(255, 255, 255)';
rate = parseInt(rating.value);
activeElement(rating);
});
});
});
const form = document.querySelector('form');
form.addEventListener('submit', e => {
e.preventDefault();
if(rate) {
localStorage.setItem("rate", rate);
form.submit();
};
});
// ====== base color
// background-color: rgba(149, 158, 172, 0.2);
// color: rgb(149, 158, 172);
// ====== hover color
// $orange: rgb(251, 116, 19);
// $white: rgb(255, 255, 255);
// ====== active color
// $light-grey: rgb(149, 158, 172);
// $white: rgb(255, 255, 255);
function hoverElement(element) {
element.addEventListener('mouseenter', () => {
element.style.backgroundColor = 'rgb(251, 116, 19)';
element.style.color = 'rgb(255, 255, 255)';
});
element.addEventListener('mouseleave', () => {
element.style.backgroundColor = 'rgba(149, 158, 172, 0.2)';
element.style.color = 'rgb(149, 158, 172)';
});
};
function activeElement(element) {
element.addEventListener('mouseenter', () => {
element.style.backgroundColor = 'rgb(149, 158, 172)';
element.style.color = 'rgb(255, 255, 255)';
});
element.addEventListener('mouseleave', () => {
element.style.backgroundColor = 'rgb(149, 158, 172)';
element.style.color = 'rgb(255, 255, 255)';
});
};