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.dataTables表格插件添加跳转到指定页
Jun 09 jQuery
jQuery、layer实现弹出层的打开、关闭功能
Jun 28 jQuery
jQuery Easyui Treegrid实现显示checkbox功能
Aug 08 jQuery
jQuery实现base64前台加密解密功能详解
Aug 29 jQuery
jQuery实现的简单图片轮播效果完整示例
Feb 08 jQuery
jQuery实现列表的增加和删除功能
Jun 14 jQuery
jQuery UI实现动画效果代码分享
Aug 19 jQuery
jQuery实现的导航条点击后高亮显示功能示例
Mar 04 jQuery
jQuery操作选中select下拉框的值代码实例
Feb 07 jQuery
jquery检测上传文件大小示例
Apr 26 jQuery
jQuery三组基本动画与自定义动画操作实例总结
May 09 jQuery
jQuery实现飞机大战小游戏
Jul 05 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 smarty模版引擎中变量操作符及使用方法
2009/12/11 PHP
php页面消耗内存过大的处理办法
2013/03/18 PHP
基于Zookeeper的使用详解
2013/05/02 PHP
解析Win7 XAMPP apache无法启动的问题
2013/06/26 PHP
php+jQuery+Ajax简单实现页面异步刷新
2016/08/08 PHP
在laravel中使用Symfony的Crawler组件分析HTML
2017/06/19 PHP
让ie6也支持websocket采用flash封装实现
2013/02/18 Javascript
图片轮换效果实现代码(点击按钮停止执行)
2013/04/12 Javascript
同域jQuery(跨)iframe操作DOM(示例代码)
2013/12/13 Javascript
Jquery实现仿腾讯娱乐频道焦点图(幻灯片)特效
2015/03/06 Javascript
JavaScript动态修改背景颜色的方法
2015/04/16 Javascript
js如何打印object对象
2015/10/16 Javascript
nodeJS微信分享
2017/12/20 NodeJs
你可能不知道的CORS跨域资源共享
2019/03/13 Javascript
nodejs微信开发之授权登录+获取用户信息
2019/03/17 NodeJs
express.js中间件说明详解
2019/03/19 Javascript
vue 集成 vis-network 实现网络拓扑图的方法
2019/08/07 Javascript
Vue全局loading及错误提示的思路与实现
2019/08/09 Javascript
vue实现学生信息管理系统
2020/05/30 Javascript
小程序自动化测试的示例代码
2020/08/11 Javascript
JS实现选项卡插件的两种写法(jQuery和class)
2020/12/30 jQuery
[27:28]Ti4 冒泡赛第二天 iG vs NEWBEE 1
2014/07/15 DOTA
python机器学习实战之最近邻kNN分类器
2017/12/20 Python
500行Python代码打造刷脸考勤系统
2019/06/03 Python
python控制台实现tab补全和清屏的例子
2019/08/20 Python
Python使用百度api做人脸对比的方法
2019/08/28 Python
Python 实现取多维数组第n维的前几位
2019/11/26 Python
python发qq消息轰炸虐狗好友思路详解(完整代码)
2020/02/15 Python
将python字符串转化成长表达式的函数eval实例
2020/05/11 Python
Python基础教程之输入输出和运算符
2020/07/26 Python
python中的列表和元组区别分析
2020/12/30 Python
支行行长竞聘报告
2014/11/06 职场文书
初一年级组工作总结
2015/08/12 职场文书
2016高一新生军训心得体会
2016/01/11 职场文书
导游词创作书写原则以及开场白技巧怎么学?
2019/09/25 职场文书
Django展示可视化图表的多种方式
2021/04/08 Python