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 相关文章推荐
Angular2使用jQuery的方法教程
May 28 jQuery
使用jQuery实现页面定时弹出广告效果
Aug 24 jQuery
Vue+jquery实现表格指定列的文字收缩的示例代码
Jan 09 jQuery
jQuery实现的电子时钟效果完整示例
Apr 28 jQuery
jQuery实现常见的隐藏与展示列表效果示例
Jun 04 jQuery
jQuery实现获取form表单内容及绑定数据到form表单操作分析
Jul 03 jQuery
jQuery实现ajax的嵌套请求案例分析
Feb 16 jQuery
jQuery中each和js中forEach的区别分析
Feb 27 jQuery
JavaScript实现的弹出遮罩层特效经典示例【基于jQuery】
Jul 10 jQuery
jQuery Ajax async=&gt;false异步改为同步时,解决导致浏览器假死的问题
Jul 22 jQuery
基于JQuery实现页面定时弹出广告
May 08 jQuery
jQuery 淡入/淡出效果函数用法分析
May 19 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中call_user_func_array()函数的用法演示
2012/02/05 PHP
Linux下php5.4启动脚本
2014/08/03 PHP
JavaScript与HTML结合的基本使用方法整理
2015/10/12 PHP
简要剖析PHP的Yii框架的组件化机制的基本知识
2016/03/17 PHP
CodeIgniter集成smarty的方法详解
2016/05/26 PHP
thinkPHP中钩子的两种配置调用方法详解
2016/11/11 PHP
JS 动态获取节点代码innerHTML分析 [IE,FF]
2009/11/30 Javascript
基于jquery的商品展示放大镜
2010/08/07 Javascript
关于JavaScript的面向对象和继承有利新手学习
2013/01/11 Javascript
你所不了解的javascript操作DOM的细节知识点(一)
2015/06/17 Javascript
jquery实现简单的轮换出现效果实例
2015/07/23 Javascript
jquery实现图片跟随鼠标的实例
2017/10/17 jQuery
node.js中路由,中间件,ge请求和post请求的参数详解
2017/12/26 Javascript
js数组方法reduce经典用法代码分享
2018/01/07 Javascript
Vue自定义指令实现checkbox全选功能的方法
2018/02/28 Javascript
vue导航栏部分的动态渲染实例
2019/11/01 Javascript
JS实现排行榜文字向上滚动轮播效果
2019/11/26 Javascript
[01:04:49]KG vs LGD 2019国际邀请赛小组赛 BO2 第二场 8.15
2019/08/16 DOTA
python清除字符串里非字母字符的方法
2015/07/02 Python
利用Python生成文件md5校验值函数的方法
2017/01/10 Python
Python实现备份MySQL数据库的方法示例
2018/01/11 Python
解决pandas中读取中文名称的csv文件报错的问题
2018/07/04 Python
Python爬取商家联系电话以及各种数据的方法
2018/11/10 Python
Python lxml解析HTML并用xpath获取元素的方法
2019/01/02 Python
Python包,__init__.py功能与用法分析
2020/01/07 Python
详解利用python识别图片中的条码(pyzbar)及条码图片矫正和增强
2020/11/17 Python
基于HTML5 FileSystem API的使用介绍
2013/04/24 HTML / CSS
苹果台湾官网:Apple台湾
2019/01/05 全球购物
护理学中专毕业生求职信
2013/11/11 职场文书
优秀大学生推荐信范文
2013/11/28 职场文书
运动会入场解说词300字
2014/01/25 职场文书
警示教育活动总结
2014/05/05 职场文书
体育教师求职信
2014/06/30 职场文书
化学专业大学生职业生涯规划范文
2014/09/13 职场文书
公司员工管理制度
2015/08/04 职场文书
2016年教师节特级教师获奖感言
2015/12/09 职场文书