jQuery实现滑动星星评分效果(每日分享)


Posted in jQuery onNovember 13, 2019

每日分享效果,今天分享一个jQuery滑动星星评分效果。

jQuery星星评分制作5颗星星鼠标滑过评分打分效果,可取消评分结果,重新打分。

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">取消评分</a><a class="blueBtn sureStar">确认</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;
}

总结

以上所述是小编给大家介绍的jQuery实现滑动星星评分效果(每日分享),希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对三水点靠木网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

jQuery 相关文章推荐
JQuery 封装 Ajax 常用方法(推荐)
May 21 jQuery
jQuery日期范围选择器附源码下载
May 23 jQuery
Jquery中attr与prop的区别详解
May 27 jQuery
jQuery 实现双击编辑表格功能
Jun 19 jQuery
基于jQuery选择器之表单对象属性筛选选择器的实例
Sep 19 jQuery
jQuery+datatables插件实现ajax加载数据与增删改查功能示例
Apr 17 jQuery
基于jquery实现左右上下移动效果
May 02 jQuery
使用jquery DataTable和ajax向页面显示数据列表的方法
Aug 09 jQuery
JQuery通过后台获取数据遍历到前台的方法
Aug 13 jQuery
jQuery pagination分页示例详解
Oct 23 jQuery
jQuery实现合并表格单元格中相同行操作示例
Jan 28 jQuery
jQuery三组基本动画与自定义动画操作实例总结
May 09 jQuery
jquery获取input输入框中的值
Nov 13 #jQuery
JS 遍历 json 和 JQuery 遍历json操作完整示例
Nov 11 #jQuery
javascript/jquery实现点击触发事件的方法分析
Nov 11 #jQuery
jquery ajax 请求小技巧实例分析
Nov 11 #jQuery
jQuery利用cookie 实现本地收藏功能(不重复无需多次命名)
Nov 07 #jQuery
jQuery实现form表单基于ajax无刷新提交方法实例代码
Nov 04 #jQuery
jQuery鼠标滑过横向时间轴样式(代码详解)
Nov 01 #jQuery
You might like
PHP的栏目导航程序
2006/10/09 PHP
PHP防注入安全代码
2008/04/09 PHP
php表单提交问题的解决方法
2011/04/12 PHP
PHP获取http请求的头信息实现步骤
2012/12/16 PHP
JS对外部文件的加载及对IFRMAME的加载的实现,当加载完成后,指定指向方法(方法回调)
2011/07/04 Javascript
使用CSS样式position:fixed水平滚动的方法
2014/02/19 Javascript
JavaScript学习笔记之检测客户端类型是(引擎、浏览器、平台、操作系统、移动设备)
2015/12/03 Javascript
js获取当前周、上一周、下一周日期
2017/03/19 Javascript
js实现图片放大展示效果
2017/08/30 Javascript
babel的使用及安装配置教程
2018/02/22 Javascript
vue2.0结合Element-ui实战案例
2019/03/06 Javascript
Vue中Table组件Select的勾选和取消勾选事件详解
2019/03/19 Javascript
angular中的post请求处理示例详解
2020/06/30 Javascript
[54:51]Ti4 冒泡赛第二轮LGD vs C9 3
2014/07/14 DOTA
[01:39:42]Fnatic vs Mineski 2018国际邀请赛小组赛BO2 第一场 8.17
2018/08/18 DOTA
linux下安装easy_install的方法
2013/02/10 Python
Python深入学习之闭包
2014/08/31 Python
Python cookbook(数据结构与算法)字典相关计算问题示例
2018/02/18 Python
Python实现对字典分别按键(key)和值(value)进行排序的方法分析
2018/12/19 Python
Python两台电脑实现TCP通信的方法示例
2019/05/06 Python
Python的条件锁与事件共享详解
2019/09/12 Python
python实现图片二值化及灰度处理方式
2019/12/07 Python
python装饰器三种装饰模式的简单分析
2020/09/04 Python
Python关于拓扑排序知识点讲解
2021/01/04 Python
python+opencv3.4.0 实现HOG+SVM行人检测的示例代码
2021/01/28 Python
CSS3结构性伪类选择器九种写法
2012/04/18 HTML / CSS
意大利体育用品网上商城:Nencini Sport
2016/08/18 全球购物
SIXPAD智能健身仪英国官网:革命性的训练装备品牌
2018/09/27 全球购物
7 For All Mankind官网:美国加州洛杉矶的高级牛仔服装品牌
2018/12/20 全球购物
保加利亚服装和鞋类购物网站:Bibloo.bg
2020/11/08 全球购物
delegate与普通函数的区别
2014/01/22 面试题
《永远的白衣战士》教学反思
2014/04/25 职场文书
自愿解除劳动合同协议书
2014/09/11 职场文书
2014年作风建设剖析材料
2014/10/23 职场文书
信息简报范文
2015/07/21 职场文书
Go获取两个时区的时间差
2022/04/20 Golang