Skip to content

Commit

Permalink
add star rating ui
Browse files Browse the repository at this point in the history
  • Loading branch information
kuldp18 committed Apr 4, 2024
1 parent 78383f6 commit 166d432
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
18 changes: 17 additions & 1 deletion css/video_page.css
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,20 @@
font-size: 1.2rem;
cursor: pointer;
}
/* Modifiers */

.star i {
color: rgba(243, 211, 28, 0.966);
transition: color 0.3s ease;
font-size: 1.25rem;
}

.star:hover i {
color: rgba(243, 211, 28, 0.966);
cursor: pointer;
}

.star:hover~.star i {
color: rgba(243, 211, 28, 0.966);
}

/* Modifiers */
34 changes: 34 additions & 0 deletions js/star_rating.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const stars = document.querySelectorAll(".far.fa-star");

let clickedStarIndex = -1; // global variable to keep track of clicked star

function hoverStar() {
stars.forEach((star, index) => {
star.addEventListener("mouseover", () => {
updateStars(index, "mouseover");
});
star.addEventListener("mouseout", () => {
updateStars(clickedStarIndex, "mouseout");
});
star.addEventListener("click", () => {
clickedStarIndex = index;
updateStars(clickedStarIndex, "click");
});
});
}

function updateStars(starIndex, eventType) {
stars.forEach((star, index) => {
if (index <= starIndex) {
star.classList.remove("far");
star.classList.add("fas");
} else {
if (eventType !== "click" || index > clickedStarIndex) {
star.classList.remove("fas");
star.classList.add("far");
}
}
});
}

hoverStar();
9 changes: 8 additions & 1 deletion pages/video_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@
<div class="player__stats__ratings">
<div class="player__stats__ratings__left">
<p class="rate">Rate this video: </p>
<span class="stars">⭐⭐⭐⭐⭐</span>
<div id="stars">
<span class="star" data-rating="1"><i class="far fa-star"></i></span>
<span class="star" data-rating="2"><i class="far fa-star"></i></span>
<span class="star" data-rating="3"><i class="far fa-star"></i></span>
<span class="star" data-rating="4"><i class="far fa-star"></i></span>
<span class="star" data-rating="5"><i class="far fa-star"></i></span>
</div>
</div>
<div class="player__stats__ratings__right">
<p class="ratings">
Expand Down Expand Up @@ -139,6 +145,7 @@


<script src="../js/close_modal.js"></script>
<script src="../js/star_rating.js"></script>

<script src="https://vjs.zencdn.net/8.10.0/video.min.js"></script>
</body>
Expand Down

0 comments on commit 166d432

Please sign in to comment.