forked from anuragverma108/SwapReads
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rate.html
153 lines (131 loc) · 3.84 KB
/
rate.html
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rate Us</title>
<style>
:root{
--old-rose: hsl(357, 37%, 62%);
--old-rose_30: hsla(357, 37%, 62%, 0.3);
--light-pink: hsl(357, 93%, 84%);
--ghost-white: hsl(233, 33%, 95%);
}
* {
margin:0;
padding: 0;
box-sizing: border-box;
}
body{
min-height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-family: Arial, Helvetica, sans-serif;
background-color: hsl(357, 37%, 62%) ;
position: relative;
}
.home_button {
position: absolute;
top: 10px;
left: 10px;
padding: 10px 20px;
background-color: #fff;
color: hsl(357, 37%, 62%);
border: none;
border-radius: 5px;
cursor: pointer;
text-decoration: none; /* To remove the default underline */
}
.rating_heading{
color: white;
animation: scale-up 1s ease;
}
@keyframes scale-up {
0%{
opacity: 0;
transform: scale(.5);
}
100%{
opacity: 1;
transform: scale(1);
}
}
.star_rating{
user-select: none;
background-color: white;
padding:1.4rem 2.5rem ;
margin: 2rem;
border-radius: .4rem;
text-align: center;
animation: slide-up 1s ease;
}
@keyframes slide-up {
0%{
opacity: 0;
transform: translateY(50px);
}
100%{
opacity: 1;
transform: translateY(0px);
}
}
.star{
font-size: 3rem;
color: #ff9800;
background-color: unset;
border: none;
}
.star:hover{
cursor: pointer;
}
/* Media Query for Responsive Design */
@media only screen and (max-width: 600px) {
/* Adjustments for smaller screens */
.star_rating {
padding: 1rem;
margin: 1rem;
}
.star {
font-size: 2rem;
}
}
</style>
</head>
<body>
<a href="index.html" class="home_button">Home</a>
<h1 class="rating_heading"> 5 Star Rating</h1>
<div class="star_rating">
<p>How was your experience?</p>
<button class="star">☆</button>
<button class="star">☆</button>
<button class="star">☆</button>
<button class="star">☆</button>
<button class="star">☆</button>
<p class="current_rating"> 0 of 5</p>
</div>
</body>
<script>
const allStars=document.querySelectorAll('.star');
console.log(allStars);
let current_rating=document.querySelector('.current_rating');
allStars.forEach((star,i)=>{// i is for index of star
star.onclick=function(){
//console.log(star);
//console.log(i+1);
let currentStar_level=i+1;
current_rating.innerText=`${currentStar_level} of 5`;
console.log(currentStar_level);
allStars.forEach((star,j)=>{
console.log(j);
if(currentStar_level>=j+1){
star.innerHTML='★';
} else{
star.innerHTML='☆';
}
})
}
})
</script>
</html>