-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
59 lines (49 loc) · 1.69 KB
/
script.js
File metadata and controls
59 lines (49 loc) · 1.69 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
//animations
const thanks = document.getElementById("thanksSection");
const rating = document.getElementById("ratingSection");
const ratingBTN = document.querySelector("#thanksSection button");
const alertMsg = document.querySelector(".alert");
const cardAlert = document.querySelector("#rateCard");
//for buttons interaction
const numberBtn = document.querySelectorAll(".num-btn");
let selectedValue = null;
//BUTTONS INTERACTION
numberBtn.forEach((element) => {
element.addEventListener("click", () => {
numberBtn.forEach((btn) => btn.classList.remove("active"));
element.classList.add("active");
selectedValue = element.getAttribute("data-value");
});
});
function submit() {
if (selectedValue) {
rating.style.opacity = "0";
ratingBTN.innerHTML = `You selected ${selectedValue} out of 5`;
rating.addEventListener(
"transitionend",
function () {
//Start after rating opacity animation has finished
rating.style.visibility = "hidden";
thanks.style.opacity = "1";
thanks.style.visibility = "visible";
},
{ once: true }
);
alertMsg.classList.remove("alert-show");
cardAlert.style.border = "none";
console.log(`Selected rate: ${selectedValue}`);
setTimeout(function () {
//reload the page after the rating was successful
window.location.reload();
}, 5000);
} else {
console.error("Please select a value first.");
alertMsg.classList.add("alert-show");
cardAlert.style.border = "1px solid var(--alert)";
//adding the shaking animation and stop it after
cardAlert.classList.add("cardShake");
setTimeout(() => {
cardAlert.classList.remove("cardShake");
}, 300);
}
}