js仿淘寶評(píng)價(jià)評(píng)分功能
更新時(shí)間:2017年02月28日 15:42:33 作者:湛瞳
本文主要介紹了js仿淘寶評(píng)價(jià)評(píng)分功能——點(diǎn)擊心形生成得分(有半心選擇),具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧
效果圖:

圖(1)初始圖

圖(2)點(diǎn)擊效果
代碼如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>文件上傳</title>
<meta name="description" content="">
<meta name="keywords" content="">
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
<style>
/*評(píng)分*/
ul{
height: 20px;
}
li{
list-style: none;
float: left;
width: 15px;
height: 20px;
}
.leftHeart{
background: url('http://cdn.attach.qdfuns.com/notes/pics/201702/28/145751uq6u6vfsnsvdbqbp.png') no-repeat bottom left;
}
.rightHeart{
background: url('http://cdn.attach.qdfuns.com/notes/pics/201702/28/145751crdjmidtdy4rmm1t.png') no-repeat bottom left;
}
.score{
font-size: 22px;
font-weight: bolder;
color: #ff0000;
}
</style>
</head>
<body onload="init()">
<!-- 評(píng)分 -->
<ul>
<li class="halfHeart leftHeart"></li><li class="halfHeart rightHeart"></li>
<li class="halfHeart leftHeart"></li><li class="halfHeart rightHeart"></li>
<li class="halfHeart leftHeart"></li><li class="halfHeart rightHeart"></li>
<li class="halfHeart leftHeart"></li><li class="halfHeart rightHeart"></li>
<li class="halfHeart leftHeart"></li><li class="halfHeart rightHeart"></li>
得分:<span class="score"></span>
</ul>
<script>
$('.halfHeart:odd').css('padding-right', '5px');
var ifHover = true,
ifClick = true;
$('.halfHeart').mouseover(function(){
if (ifHover) {
for (var i = 0; i <= $(this).index(); i++) {
$('.halfHeart').eq(i).css('background-position', 'top left');
}
$('.score').text(($(this).index()+1) * 0.5);
}
})
$('.halfHeart').mouseout(function(){
if (ifHover) {
for (var i = 0; i <= $(this).index(); i++) {
$('.halfHeart').eq(i).css('background-position', 'bottom left');
}
}
})
$('.halfHeart').click(function(){
if (ifClick) {
ifHover = false;
ifClick = false;
for (var i = 0; i <= $(this).index(); i++) {
$('.halfHeart').eq(i).css('background-position', 'top left');
}
$('.score').text(($(this).index()+1) * 0.5);
}
})
</script>
</body>
</html>
以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!
相關(guān)文章
vue3 uniapp微信登錄功能實(shí)現(xiàn)
根據(jù)最新的微信小程序官方的規(guī)定,uniapp中的uni.getUserInfo方法不再返回用戶頭像和昵稱、以及手機(jī)號(hào),這篇文章主要介紹了vue3 uniapp微信登錄功能實(shí)現(xiàn),需要的朋友可以參考下2024-04-04
js調(diào)用百度地圖及調(diào)用百度地圖的搜索功能
本文給大家介紹js調(diào)用百度地圖的方法以及調(diào)用百度地圖的搜索功能,有需要的朋友可以跟著腳本之家的小編一起學(xué)習(xí)2015-09-09
JavaScript樹形結(jié)構(gòu)數(shù)組處理之遞歸問(wèn)題
這篇文章主要介紹了JavaScript樹形結(jié)構(gòu)數(shù)組處理之遞歸問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06
JavaScript中concat復(fù)制數(shù)組方法淺析
在本篇文章里小編給大家總結(jié)了關(guān)于JavaScript中concat復(fù)制數(shù)組方法知識(shí)點(diǎn),有需要的朋友們可以學(xué)習(xí)下。2019-01-01

