Looking for a simple solution here. I'm working on coding a 5-star rating system.
I have an array set up with 5 possible ratings:
const ratingsArray = [
{
name: 'rating1',
ratingValue: 20,
isEnabled: ref(false)
},
{
name: 'rating2',
ratingValue: 40,
isEnabled: ref(false)
},
{
name: 'rating3',
ratingValue: 60,
isEnabled: ref(false)
},
{
name: 'rating4',
ratingValue: 80,
isEnabled: ref(false)
},
{
name: 'rating5',
ratingValue: 100,
isEnabled: ref(false)
},
]
This template loops through the array and displays a circle for each entry:
The class 'ratingBoxChecked' is applied to fill the dot with color.
<template>
<span>
<div
v-for="(rating, index) in ratingsArray"
:key="rating.name"
@click="updateRating(index, rating.ratingValue)"
:class="[rating.isEnabled.value ? 'ratingBoxChecked' : 'ratingBox']">
</div>
</span>
</template>
Is there a way to hover over one dot and have the previous ones hovered as well all with the class 'ratingBoxChecked'?
For instance, if I hover over the 3rd dot, I want the first 2 dots to also be enabled! Just like a typical star rating hover effect.
Appreciate any help you can provide!