I'm developing a Java map using a leaflet and I'm creating marker popups on the map. On these popups, I would like to have a star rating system that on hover highlights all stars beforehand, and on click, the stars stay filled. Currently, I can make them remain filled on click but only highlight one at a time with hover.
This is my CSS for the stars currently:
/*set the default color of the stars*/
.star-rating{
color: #bebebe;
font-size:2em;
}
/*create the star*/
.my-star:before{
content:"\002605";
}
/*remove the default style (italic) of the star*/
.my-star{
font-style: unset !important;
width: px;
}
/*set active star color*/
.is-active{
color:#fb8900;
}
/*set color on hover*/
.my-star:hover{
color: #fb8900;
}
This is my Javascript code for making an individual star element (this is repeated 5 times with the numbers being incremented).
var popupStar1 = document.createElement("i");
popupStar1.className ="my-star star-1";
popupStar1.setAttribute("data-star", "1");
This is then appended to a 'p' element, which is then appended to the marker 'div' element:
var popupRating = document.createElement("p");
popupRating.className ="star-rating";
popupRating.append(popupStar1);
popupRating.append(popupStar2);
popupRating.append(popupStar3);
popupRating.append(popupStar4);
popupRating.append(popupStar5);
popupDiv.append(popupRating);
This is the resulting HTML:
<p class="star-rating">
<i class="my-star star-1" data-star="1"></i>
<i class="my-star star-2" data-star="2"></i>
<i class="my-star star-3" data-star="3"></i>
<i class="my-star star-4" data-star="4"></i>
<i class="my-star star-5" data-star="5"></i>
</p>