-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRating.js
More file actions
61 lines (49 loc) · 1.53 KB
/
Rating.js
File metadata and controls
61 lines (49 loc) · 1.53 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
window.onload = function() {
var items = document.querySelectorAll('.item');
// 1. lighten the star when mouse is over the star items
function overStar() {
//var id = parseInt(this.id,10)
for (let i = 0; i < this.id; i++) {
items[i].classList.add('over');
}
}
// add listner to each star items
for (let i = 0; i < items.length; i++) {
items[i].addEventListener('mouseover', overStar)
};
// 2. turn off star when the mouse leave that star, and is over another star
function leaveStar() {
if (!star - container.classList.contains('clicked')) {
for (let i = 0; i < this.id; i++) {
items[i].classList.remove('over')
}
}
}
// add listner to each star items
for (let i = 0; i < items.length; i++) {
items[i].addEventListener('mouseleave', leaveStar)
};
// 3. pop up the sescription text when clicked
function clicked() {
// remove current poped text
let currOnElem = document.querySelector('.popText');
// in case currOnELem is null value
if (currOnElem) {
currOnElem.classList.remove('popText');
}
for (let i = this.id; i < items.length; i++) {
items[i].classList.remove('over')
}
// pop corresponding text
let targetElemId = 'description' + this.id;
targetElemId = '#' + targetElemId;
let targetElem = document.querySelector(targetElemId);
targetElem.classList.add('popText')
// add clicked to class list
star - container.classList.add('clicked')
}
// add listner to each star items
for (let i = 0; i < items.length; i++) {
items[i].addEventListener('click', clicked)
};
};