您好,登錄后才能下訂單哦!
每日分享效果,今天分享一個(gè)jQuery滑動(dòng)星星評(píng)分效果。
jQuery星星評(píng)分制作5顆星星鼠標(biāo)滑過評(píng)分打分效果,可取消評(píng)分結(jié)果,重新打分。
HTML代碼:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="css/css.css">
<script src="js/jquery.js"></script>
</head>
<body>
<div id="starRating">
<p class="photo">
<span><i class="high"></i><i class="nohigh"></i></span>
<span><i class="high"></i><i class="nohigh"></i></span>
<span><i class="high"></i><i class="nohigh"></i></span>
<span><i class="high"></i><i class="nohigh"></i></span>
<span><i class="high"></i><i class="nohigh"></i></span>
</p>
<p class="starNum">0.0分</p>
<div class="bottoms">
<a class="garyBtn cancleStar">取消評(píng)分</a><a class="blueBtn sureStar">確認(rèn)</a>
</div>
</div>
<script>
$(function () {
//評(píng)分
var starRating = 0;
$('.photo span').on('mouseenter',function () {
var index = $(this).index()+1;
$(this).prevAll().find('.high').css('z-index',1)
$(this).find('.high').css('z-index',1)
$(this).nextAll().find('.high').css('z-index',0)
$('.starNum').html((index*2).toFixed(1)+'分')
})
$('.photo').on('mouseleave',function () {
$(this).find('.high').css('z-index',0)
var count = starRating / 2
if(count == 5) {
$('.photo span').find('.high').css('z-index',1);
} else {
$('.photo span').eq(count).prevAll().find('.high').css('z-index',1);
}
$('.starNum').html(starRating.toFixed(1)+'分')
})
$('.photo span').on('click',function () {
var index = $(this).index()+1;
$(this).prevAll().find('.high').css('z-index',1)
$(this).find('.high').css('z-index',1)
starRating = index*2;
$('.starNum').html(starRating.toFixed(1)+'分');
alert('評(píng)分:'+(starRating.toFixed(1)+'分'))
})
//取消評(píng)分
$('.cancleStar').on('click',function () {
starRating = 0;
$('.photo span').find('.high').css('z-index',0);
$('.starNum').html(starRating.toFixed(1)+'分');
})
//確定評(píng)分
$('.sureStar').on('click',function () {
if(starRating===0) {
alert('最低一顆星!');
} else {
alert('評(píng)分:'+(starRating.toFixed(1)+'分'))
}
})
})
</script>
</body>
</html>
CSS代碼:
#starRating .photo span {
position: relative;
display: inline-block;
width: 44px;
height: 42px;
overflow: hidden;
margin-right: 23px;
cursor: pointer;
}
#starRating .photo span:last-child {
margin-right: 0px;
}
#starRating .photo span .nohigh {
position: absolute;
width: 44px;
height: 42px;
top: 0;
left: 0;
background: url("../img/star.png");
}
#starRating .photo span .high {
position: absolute;
width: 44px;
height: 42px;
top: 0;
left: 0;
background: url("../img/star1.png");
}
#starRating .starNum {
font-size: 26px;
color: #de4414;
margin-top: 4px;
margin-bottom: 10px;
}
#starRating .bottoms {
height: 54px;
border-top: 1px solid #d8d8d8;
}
#starRating .photo {
margin-top: 30px;
}
#starRating .bottoms a {
margin-bottom: 0;
}
#starRating .bottoms .garyBtn {
margin-right: 57px!important;
}
#starRating .bottoms a {
width: 130px;
height: 35px;
line-height: 35px;
border-radius: 3px;
display: inline-block;
font-size: 16px;
transition: all 0.2s linear;
margin: 16px 0 22px;
text-align: center;
cursor: pointer;
}
.garyBtn {
margin-right: 60px!important;
background-color: #e1e1e1;
color: #999999;
}
.blueBtn {
background-color: #1968b1;
color: #fff;
}
.blueBtn:hover {
background: #0e73d0;
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。