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实现简单的手风琴效果
Apr 17 jQuery
jQuery制作input提示内容(兼容IE8以上)
Jul 05 jQuery
利用JQUERY实现多个AJAX请求等待的实例
Dec 14 jQuery
jQuery+datatables插件实现ajax加载数据与增删改查功能示例
Apr 17 jQuery
JQuery元素快速查找与操作
Apr 22 jQuery
jQuery实现常见的隐藏与展示列表效果示例
Jun 04 jQuery
使用jquery Ajax实现上传附件功能
Oct 23 jQuery
jquery ui 实现 tab标签功能示例【测试可用】
Jul 25 jQuery
jQuery实现简单弹幕效果
Nov 28 jQuery
jQuery 函数实例分析【函数声明、函数表达式、匿名函数等】
May 19 jQuery
jQuery实现放大镜案例
Oct 19 jQuery
ajax jquery实现页面某一个div的刷新效果
Mar 04 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
vs中通过剪切板循环来循环粘贴不同内容
2011/04/30 PHP
PHP中使用gettext来支持多语言的方法
2011/05/02 PHP
php中通用的excel导出方法实例
2017/12/30 PHP
php实现session共享的实例方法
2019/09/19 PHP
html的DOM中Event对象onblur事件用法实例
2015/01/21 Javascript
Javascript动态创建div的方法
2015/02/09 Javascript
jquery实现隐藏在左侧的弹性弹出菜单效果
2015/09/18 Javascript
深入探究JavaScript中for循环的效率问题及相关优化
2016/03/13 Javascript
jQuery实现根据滚动条位置加载相应内容功能
2016/07/18 Javascript
Vue.js 2.0学习教程之从基础到组件详解
2017/04/24 Javascript
bootstrap响应式工具使用详解
2017/11/29 Javascript
react-native使用leanclound消息推送的方法
2018/08/06 Javascript
js实现继承的方法及优缺点总结
2019/05/08 Javascript
Layui 带多选框表格监听事件以及按钮自动点击写法实例
2019/09/02 Javascript
vue 使用 canvas 实现手写电子签名
2020/03/06 Javascript
基于js实现逐步显示文字输出代码实例
2020/04/02 Javascript
JavaScript实现简单的弹窗效果
2020/05/19 Javascript
Vue使用Proxy代理后仍无法生效的解决
2020/11/13 Javascript
[08:44]DOTA2发布会群星聚首 我们都是刀塔人
2014/03/21 DOTA
python 动态获取当前运行的类名和函数名的方法
2014/04/15 Python
详解Python自建logging模块
2018/01/29 Python
详解爬虫被封的问题
2019/04/23 Python
Django 对象关系映射(ORM)源码详解
2019/08/06 Python
Ubuntu配置Pytorch on Graph (PoG)环境过程图解
2020/11/19 Python
详解HTML5通讯录获取指定多个人的信息
2016/12/20 HTML / CSS
加拿大在线旅游公司:Flighthub
2019/03/11 全球购物
解释i节点在文件系统中的作用
2013/11/26 面试题
商业融资计划书
2014/04/29 职场文书
车贷收入证明范本
2014/09/14 职场文书
小学生纪念九一八事变演讲稿
2014/09/14 职场文书
销售人才自我评价范文
2014/09/27 职场文书
单位接收函格式
2015/01/30 职场文书
中英文求职信范文
2015/03/19 职场文书
警告通知
2015/04/25 职场文书
公司人事管理制度
2015/08/05 职场文书
百年校庆宣传标语口号
2015/12/26 职场文书