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插件FusionCharts绘制2D柱状图和折线图的组合图效果示例【附demo源码】
Apr 10 jQuery
JS和jQuery通过this获取html标签中的属性值(实例代码)
Sep 11 jQuery
jQuery实现火车票买票城市选择切换功能
Sep 15 jQuery
jQuery实现左右滑动的toggle方法
Mar 03 jQuery
AJAX在JQuery中的应用详解
Jan 30 jQuery
JS/jQuery实现获取时间的方法及常用类完整示例
Mar 07 jQuery
jQuery实现动态生成年月日级联下拉列表示例
May 11 jQuery
JQuery使用属性addClass、removeClass和toggleClass实现增加和删除类操作示例
Nov 18 jQuery
jquery向后台提交数组的代码分析
Feb 20 jQuery
jquery css实现流程进度条
Mar 26 jQuery
jQuery实现日历效果
Sep 11 jQuery
jQuery实现影院选座订座效果
Apr 13 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的ob_start来生成静态页面的方法分析
2011/03/09 PHP
浅谈ThinkPHP的URL重写
2014/11/25 PHP
PHP Yii框架之表单验证规则大全
2015/11/16 PHP
Windows2003下php5.4安装配置教程(IIS)
2016/06/30 PHP
php+croppic.js实现剪切上传图片功能
2018/08/14 PHP
浅谈Laravel核心解读之Console内核
2018/12/02 PHP
Javascript下IE与Firefox下的差异兼容写法总结
2010/06/18 Javascript
javascript实现日历控件(年月日关闭按钮)
2012/12/12 Javascript
Extjs中通过Tree加载右侧TabPanel具体实现
2013/05/05 Javascript
node.js中的fs.writeFileSync方法使用说明
2014/12/14 Javascript
浅谈关于JavaScript API设计的一些建议和准则
2015/06/24 Javascript
Bootstrap中定制LESS-颜色及导航条(推荐)
2016/11/21 Javascript
jquery+ajax实现省市区三级联动 (封装和不封装两种方式)
2017/05/15 jQuery
详解angularJS+Ionic移动端图片上传的解决办法
2017/09/13 Javascript
JS获取当前时间的实例代码(昨天、今天、明天)
2018/11/13 Javascript
Javascript 模拟mvc实现点餐程序案例详解
2020/12/24 Javascript
python笔记(1) 关于我们应不应该继续学习python
2012/10/24 Python
在Python的Django框架中包装视图函数
2015/07/20 Python
Python内存管理方式和垃圾回收算法解析
2017/11/11 Python
Flask 让jsonify返回的json串支持中文显示的方法
2018/03/26 Python
python实现视频分帧效果
2019/05/31 Python
pyqt 多窗口之间的相互调用方法
2019/06/19 Python
python pandas获取csv指定行 列的操作方法
2019/07/12 Python
Windows10+anacond+GPU+pytorch安装详细过程
2020/03/24 Python
Python异常原理及异常捕捉实现过程解析
2020/03/25 Python
python轮询机制控制led实例
2020/05/03 Python
GNC健安喜官方海外旗舰店:美国著名保健品牌
2017/01/04 全球购物
加拿大在线隐形眼镜和眼镜店:VisionPros
2019/10/06 全球购物
常见的软件开发流程有哪些
2015/11/14 面试题
活动总结模板
2014/05/09 职场文书
七年级数学教学反思
2016/02/17 职场文书
2016年万圣节活动总结
2016/04/05 职场文书
MySQL InnoDB ReplicaSet(副本集)简单介绍
2021/04/24 MySQL
pandas 实现将NaN转换为None
2021/05/14 Python
Nginx 匹配方式
2022/05/15 Servers
正则表达式基础与常用验证表达式
2022/06/16 Javascript