首页 / JQUERY / jQuery滑动星星评分效果
jQuery滑动星星评分效果
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了jQuery滑动星星评分效果,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3302字,纯文字阅读大概需要5分钟。
内容图文
每日分享效果,今天分享一个jQuery滑动星星评分效果。jQuery星星评分制作5颗星星鼠标滑过评分打分效果,可取消评分结果,重新打分。
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 >
<p >
<span><i ></i><i ></i></span>
<span><i ></i><i ></i></span>
<span><i ></i><i ></i></span>
<span><i ></i><i ></i></span>
<span><i ></i><i ></i></span>
</p>
<p >0.0分</p>
<div >
<a >取消评分</a><a >确认</a>
</div>
</div>
<script>
$(function () {
//评分
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(‘评分:‘+(starRating.toFixed(1)+‘分‘))
})
//取消评分
$(‘.cancleStar‘).on(‘click‘,function () {
starRating = 0;
$(‘.photo span‘).find(‘.high‘).css(‘z-index‘,0);
$(‘.starNum‘).html(starRating.toFixed(1)+‘分‘);
})
//确定评分
$(‘.sureStar‘).on(‘click‘,function () {
if(starRating===0) {
alert(‘最低一颗星!‘);
} else {
alert(‘评分:‘+(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;
}
原文:https://blog.51cto.com/14535203/2447819
内容总结
以上是互联网集市为您收集整理的jQuery滑动星星评分效果全部内容,希望文章能够帮你解决jQuery滑动星星评分效果所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。