我有一个Angular 项目,其组件如下所示:
<div class="stars-container mt-2">
<div *ngFor="let star of starsArray; let i = index" class="star">
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 24 24">
<path fill="#ffffff"
d="m7.69 19.346l1.614-5.33L5.115 11h5.216L12 5.462L13.67 11h5.215l-4.189 3.015l1.614 5.331L12 16.07z" />
</svg>
</div>
</div>
其中startsArray为:
starsArray: boolean[] = new Array(5);
公务员叙用计划是:
.stars-container {
display: flex;
justify-content: left;
align-items: center;
gap: .7rem;
cursor: pointer;
flex-direction: row-reverse;
.star {
transition: .3s ease;
svg {
width: 3rem;
height: auto;
path {
fill: $gris; // Color de las estrellas no seleccionadas
transition: fill .3s ease; // Transición suave del color
}
}
&:hover~.star svg path {
fill: $primario; // Color de las estrellas seleccionadas al hacer hover
}
&:hover svg path {
fill: $primario; // Color de la estrella seleccionada al hacer hover
}
}
}
.star:hover svg path,
.star:hover~.star svg path,
.star.highlighted svg path {
fill: $primario;
}
此时此刻,我已经实现了当我在一颗星星上悬停时,左边的星星也会改变 colored颜色 .尽管如此,我希望当我按下一个星号时,左侧的所有星号和被点击的星号都会永久地改变 colored颜色 (在浏览器会话中永久改变,在数据库中不会).
我试了几种方法,但都不管用.