-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
41 lines (39 loc) · 1.16 KB
/
script.js
File metadata and controls
41 lines (39 loc) · 1.16 KB
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
const starCont = document.querySelector('.star-container');
const allStars = document.querySelectorAll('.star');
const count = document.getElementById('count');
let idx = 0;
let clickFlag = false;
starCont.addEventListener('mouseover', function(e){
allStars.forEach(function(str){
str.classList.remove('star-filled');
});
idx = 0;
if(e.target.classList[0] === 'star'){
idx = e.target.getAttribute('data-index');
allStars.forEach(function(str){
if(str.getAttribute('data-index') <= idx){
str.classList.add('star-filled');
}
});
}
});
starCont.addEventListener('mouseout', function(e){
if(!clickFlag){
allStars.forEach(function(str){
str.classList.remove('star-filled');
});
idx = 0;
}
});
starCont.addEventListener('click', function(e){
clickFlag = true;
if(e.target.classList[0] === 'star'){
idx = e.target.getAttribute('data-index');
allStars.forEach(function(str){
if(str.getAttribute('data-index') <= idx){
str.classList.add('star-filled');
}
});
count.innerText = idx;
}
})