gpt4 book ai didi

javascript - 星级评定系统,给予独一无二的评价

转载 作者:行者123 更新时间:2023-11-30 11:49:20 25 4
gpt4 key购买 nike

我正在使用星标系统对数据库中的一些电影进行评级,我在一个 while 循环中添加这些电影,并在每部电影中添加星标。

我希望用户对每部电影给予独特的评价,比如如果用户给一部电影打了五颗星,那么如果他试图再次给另一部电影打五颗星,则必须有一些指示显示 在提交评级之前,将星星从黄色变为红色。谁能给我一些 sample 。

.star-rating {
font-size: 0;
white-space: nowrap;
display: inline-block;
/* width: 250px; remove this */
height: 50px;
overflow: hidden;
position: relative;
background: url('data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB3aWR0aD0iMjBweCIgaGVpZ2h0PSIyMHB4IiB2aWV3Qm94PSIwIDAgMjAgMjAiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDIwIDIwIiB4bWw6c3BhY2U9InByZXNlcnZlIj48cG9seWdvbiBmaWxsPSIjREREREREIiBwb2ludHM9IjEwLDAgMTMuMDksNi41ODMgMjAsNy42MzkgMTUsMTIuNzY0IDE2LjE4LDIwIDEwLDE2LjU4MyAzLjgyLDIwIDUsMTIuNzY0IDAsNy42MzkgNi45MSw2LjU4MyAiLz48L3N2Zz4=');
background-size: contain;
}
.star-rating i {
opacity: 0;
position: absolute;
left: 0;
top: 0;
height: 100%;
/* width: 20%; remove this */
z-index: 1;
background: url('data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB3aWR0aD0iMjBweCIgaGVpZ2h0PSIyMHB4IiB2aWV3Qm94PSIwIDAgMjAgMjAiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDIwIDIwIiB4bWw6c3BhY2U9InByZXNlcnZlIj48cG9seWdvbiBmaWxsPSIjRkZERjg4IiBwb2ludHM9IjEwLDAgMTMuMDksNi41ODMgMjAsNy42MzkgMTUsMTIuNzY0IDE2LjE4LDIwIDEwLDE2LjU4MyAzLjgyLDIwIDUsMTIuNzY0IDAsNy42MzkgNi45MSw2LjU4MyAiLz48L3N2Zz4=');
background-size: contain;
}
.star-rating input {
-moz-appearance: none;
-webkit-appearance: none;
opacity: 0;
display: inline-block;
/* width: 20%; remove this */
height: 100%;
margin: 0;
padding: 0;
z-index: 2;
position: relative;
}
.star-rating input:hover + i,
.star-rating input:checked + i {
opacity: 1;
}
.star-rating i ~ i {
width: 40%;
}
.star-rating i ~ i ~ i {
width: 60%;
}
.star-rating i ~ i ~ i ~ i {
width: 80%;
}
.star-rating i ~ i ~ i ~ i ~ i {
width: 100%;
}
::after,
::before {
height: 100%;
padding: 0;
margin: 0;
box-sizing: border-box;
text-align: center;
vertical-align: middle;
}
.star-rating.star-5 {
width: 250px;
}
.star-rating.star-5 input,
.star-rating.star-5 i {
width: 20%;
}
.star-rating.star-5 i ~ i {
width: 40%;
}
.star-rating.star-5 i ~ i ~ i {
width: 60%;
}
.star-rating.star-5 i ~ i ~ i ~ i {
width: 80%;
}
.star-rating.star-5 i ~ i ~ i ~ i ~i {
width: 100%;
}
.star-rating.star-3 {
width: 150px;
}
.star-rating.star-3 input,
.star-rating.star-3 i {
width: 33.33%;
}
.star-rating.star-3 i ~ i {
width: 66.66%;
}
.star-rating.star-3 i ~ i ~ i {
width: 100%;
}
<form method="get" action="" id="form1">
<span class="star-rating star-5">
<input type="radio" name="rating" value="1"><i></i>
<input type="radio" name="rating" value="2"><i></i>
<input type="radio" name="rating" value="3"><i></i>
<input type="radio" name="rating" value="4"><i></i>
<input type="radio" name="rating" value="5"><i></i>
</span>
</form>

此外,一旦问题解决,我将使用 PHP 存储评级。下面是我正在使用的代码。

感谢任何帮助:-)``

最佳答案

添加一个类 already-given 到已经给定的评级,这样如果这个类与以前的 star-rating 类一起出现,它将使用橙色星

.star-rating.already input:hover+ i
{
background: url('/*Url of orange star*/');!important
}

<form method="get" action="" id="form1">
<span class="star-rating star-5 already-given">
<input type="radio" name="rating" value="1"><i></i>
<input type="radio" name="rating" value="2"><i></i>
<input type="radio" name="rating" value="3"><i></i>
<input type="radio" name="rating" value="4" checked><i></i>
<input type="radio" name="rating" value="5"><i></i>
</span>
</form>

Jquery代码

$(document).ready(function(){
$("input[type=radio]").on("change",function(){
$(this).parents(".star-rating").removeClass("already-given").addClass("already-given");
});
});

编辑:

Jsfiddle demo (请删除带有橙色星号 url 的红色)

Check this also (按照评论中的要求进行的更改)

关于javascript - 星级评定系统,给予独一无二的评价,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39970682/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com