jQuery實(shí)現(xiàn)滑動(dòng)星星評(píng)分效果(每日分享)
每日分享效果,今天分享一個(gè)jQuery滑動(dòng)星星評(píng)分效果。
jQuery星星評(píng)分制作5顆星星鼠標(biāo)滑過(guò)評(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" rel="external nofollow" >
<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;
}
總結(jié)
以上所述是小編給大家介紹的jQuery實(shí)現(xiàn)滑動(dòng)星星評(píng)分效果(每日分享),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
- jQuery Raty 一款不錯(cuò)的星級(jí)評(píng)分插件
- jQuery+PHP星級(jí)評(píng)分實(shí)現(xiàn)方法
- jQuery超贊的評(píng)分插件(8款)
- jQuery動(dòng)態(tài)星級(jí)評(píng)分效果實(shí)現(xiàn)方法
- jquery實(shí)現(xiàn)用戶(hù)打分評(píng)分特效
- jquery插件star-rating.js實(shí)現(xiàn)星級(jí)評(píng)分特效
- 使用jQuery實(shí)現(xiàn)星級(jí)評(píng)分代碼分享
- jquery實(shí)現(xiàn)類(lèi)似淘寶星星評(píng)分功能有截圖
- jquery實(shí)現(xiàn)類(lèi)似淘寶星星評(píng)分功能實(shí)例
- jquery五角星評(píng)分插件示例分享
- jQuery插件-jRating評(píng)分插件源碼分析及使用方法
- 基于jQuery的星級(jí)評(píng)分插件
相關(guān)文章
基于jquery的loading效果實(shí)現(xiàn)代碼
基于jquery的loading效果實(shí)現(xiàn)代碼,需要的朋友可以參考下。2010-11-11
jQuery.datatables.js插件用法及api實(shí)例詳解
這篇文章主要介紹了jquery插件之jQuery.datatables.js用法及api實(shí)例詳解,本文給大家介紹的非常詳細(xì)具有參考借鑒價(jià)值,需要的朋友可以參考下2016-10-10
Jquery輪播效果實(shí)現(xiàn)過(guò)程解析
這篇文章主要為大家詳細(xì)的分析了Jquery輪播效果實(shí)現(xiàn)過(guò)程的具體步驟以及實(shí)現(xiàn)思路,幫助大家快速實(shí)現(xiàn)Jquery輪播效果,感興趣的小伙伴們可以參考一下2016-03-03
jquery實(shí)現(xiàn)手機(jī)端單店鋪購(gòu)物車(chē)結(jié)算刪除功能
本文主要介紹了js實(shí)現(xiàn)手機(jī)端單店鋪購(gòu)物車(chē)結(jié)算刪除功能的示例代碼,具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-02-02
easyUI combobox實(shí)現(xiàn)聯(lián)動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了easyUI combobox實(shí)現(xiàn)聯(lián)動(dòng)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01

