使用jQuery实现点评星星效果

2024-03-16 11:08

本文主要是介绍使用jQuery实现点评星星效果,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

使用jQuery实现点评星星效果


 


 

 

没什么好说的,直接上代码吧

 

1. html代码

 

Html代码   收藏代码
  1. <table class="block">  
  2.     <tr>  
  3.         <td>  
  4.             <span class="label">总体评价<em>*</em>:</span>  
  5.         </td>  
  6.         <td>  
  7.             <div class="rating-wrap">  
  8.                 <ul class="rating-wrap-ul"  onmouseout="onUlMouseOut()" onmouseover="onUlMouseOver()">  
  9.                     <li><a class="one-star" title="很差" data-hint="很差" href="javascript:clickStar(1);" onmouseover="onLiMouseOver(1)" onmouseout="onLiMouseOut()"></a></li>  
  10.                     <li><a class="two-stars" title="差" data-hint="差" href="javascript:clickStar(2);" onmouseover="onLiMouseOver(2)" onmouseout="onLiMouseOut()"></a></li>  
  11.                     <li><a class="three-stars" title="还行" data-hint="还行" href="javascript:clickStar(3);" onmouseover="onLiMouseOver(3)" onmouseout="onLiMouseOut()"></a></li>  
  12.                     <li><a class="four-stars" title="好" data-hint="好" href="javascript:clickStar(4);" onmouseover="onLiMouseOver(4)" onmouseout="onLiMouseOut()"></a></li>  
  13.                     <li><a class="five-stars" title="很好" data-hint="很好" href="javascript:clickStar(5);" onmouseover="onLiMouseOver(5)" onmouseout="onLiMouseOut()"></a></li>  
  14.                 </ul>  
  15.             </div>  
  16.             <span id="ratingText" class="active-hint" innerText=""></span>  
  17.         </td>  
  18.     </tr>  
  19.     <tr>  
  20.         <td>  
  21.             <span class="label">评价<em>*</em>:</span>  
  22.         </td>  
  23.         <td>  
  24.             <span class="note">(50-2000个字)</span>  
  25.             <span id="textCount" class="note" innerText=""></span>  
  26.         </td>  
  27.     </tr>  
  28.     <tr>  
  29.         <td>  
  30.         </td>  
  31.         <td>  
  32.             <textarea name="appraiseText" id="appraiseText" class="form-content-block form-textarea" rows="12"></textarea>  
  33.         </td>  
  34.     </tr>  
  35.     <tr>  
  36.         <td>  
  37.         </td>  
  38.         <td align="right">  
  39.             <input type="button" value="提交" onclick="submitAppraise()">  
  40.             <input type="button" value="关闭" onclick=" ">  
  41.         </td>  
  42.     </tr>  
  43. </table>  

 

 

2. 所需要的css

 

Css代码   收藏代码
  1. body {  
  2.     color: #333;  
  3.     font: normal normal normal 12px/1.5 Arial, 宋体, sans-serif;  
  4. }  
  5. .block{  
  6.     clear: both;  
  7.     margin-bottom:20px;  
  8.     margin-bottom: 10px;  
  9.     zoom: 1;  
  10.     padding:5px 11px;border:1px solid #F5EEE8;  
  11.     padding-top:10px;margin:0 10px 0;  
  12.     padding-bottom:20px;border-bottom:1px dashed #E4E4E4;  
  13.     margin:10px auto;padding:0;border:none;  
  14. }  
  15.   
  16. .label{  
  17.     float:right;  
  18.     margin-right: 10px;  
  19.     text-align: right;  
  20.     font-weight: normal;  
  21.     font-style:normal;  
  22.     width: 94px;  
  23. }  
  24. em{  
  25.     margin-right:5px;  
  26.     color:#c00;  
  27.     font-weight:bold;  
  28.     font-style:normal;  
  29.     margin-left:2px;  
  30. }  
  31. .note {  
  32.     color: #999;  
  33. }  
  34.   
  35. .form-textarea{  
  36.     float: left;  
  37.     font-family: Tahoma, Geneva, sans-serif;  
  38.     margin-right: 5px;  
  39.     width: 598px;  
  40.     zoom: 1;  
  41.     font-family: inherit;  
  42.     font-size: 100%;  
  43.     -webkit-appearance: textarea;  
  44.     -webkit-box-orient: vertical;  
  45.     -webkit-rtl-ordering: logical;  
  46.     -webkit-user-select: text;  
  47.     background-color: white;  
  48.     border: 1px solid;  
  49.     cursor: auto;  
  50.     padding: 2px;  
  51.     resize: auto;  
  52.     white-space: pre-wrap;  
  53.     word-wrap: break-word;  
  54. }  
  55.           
  56. .rating-wrap {  
  57.     display: inline-block;  
  58.     float: left;  
  59.     position: relative;  
  60.     top: -2px;  
  61.     width: 89px;  
  62.     height: 20px;  
  63.     margin-right: 5px;  
  64.     padding: 4px 0 0 5px;  
  65.     border: 1px solid #EFE0D7;  
  66.     background: #FFF9F1;  
  67.     z-index: 0;  
  68. }  
  69. .rating-wrap ul,.rating-wrap a:hover {  
  70.     background-image: url(../images/star_shade.png);  
  71.     background-repeat: no-repeat;  
  72. }  
  73.   
  74. .rating-wrap ul {  
  75.     -webkit-padding-start: 40px;  
  76.     display: block;  
  77.     list-style-type: disc;  
  78.     margin: 1em 0px;  
  79.     border: 0px;  
  80.     margin: 0px;  
  81.     outline: 0px;  
  82.     padding: 0px;  
  83.     list-style: none;  
  84.     position: relative;  
  85.     width: 85px;  
  86.     height: 16px;  
  87.     background-position: 0 -90px;  
  88.     z-index: 10;  
  89. }  
  90.   
  91. .rating-wrap li {  
  92.     display: inline;  
  93. }  
  94.   
  95. .rating-wrap a {  
  96.     zoom: 1;  
  97.     position: absolute;  
  98.     left: 0;  
  99.     top: 0;  
  100.     display: block;  
  101.     height: 16px;  
  102. }  
  103.   
  104. .rating-wrap .five-stars {  
  105.     width: 84px;  
  106.     z-index: 10;  
  107.     background-position: 0 0px;  
  108. }  
  109.   
  110. .rating-wrap .four-stars {  
  111.     width: 68px;  
  112.     z-index: 20;  
  113.     background-position: 0 -18px;  
  114. }  
  115.   
  116. .rating-wrap .three-stars {  
  117.     width: 51px;  
  118.     z-index: 30;  
  119.     background-position: 0 -36px;  
  120. }  
  121.   
  122. .rating-wrap .two-stars {  
  123.     width: 34px;  
  124.     z-index: 40;  
  125.     background-position: 0 -54px;  
  126. }  
  127.   
  128. .rating-wrap .one-star {  
  129.     width: 17px;  
  130.     z-index: 50;  
  131.     background-position: 0 -72px;  
  132. }  
  133.   
  134. .active-hint{  
  135.     color: #C00;  
  136.     float: left;  
  137.     padding-top:2px;  
  138.     font-weight: normal;  
  139.     font-style:normal;  
  140. }  

 

 

3. 所需要的javascript代码

 

Js代码   收藏代码
  1. $(document).ready(function(){  
  2.     $("#appraiseText").bind("keydown"function(){  
  3.         var count = $("#appraiseText").val().length;  
  4.         if( count <= 200 ){  
  5.             $("#textCount").html(" 还能输入<font color='green'><b>" + (200 - count) + "</b></font>个字");  
  6.         }else{  
  7.             $("#textCount").html(" 已超出<font color='red'><b>" + (count - 200) + "</b></font>个字");  
  8.         }  
  9.     });   
  10. });  
  11.   
  12. var starValue=0;  
  13. function onUlMouseOut(){  
  14.     var y = -90 + starValue * 18;  
  15.     var position = "0 " + y + "px";  
  16.     $(".rating-wrap-ul").css({  
  17.         "background-position" : position  
  18.     });  
  19. }  
  20.   
  21. function onUlMouseOver(){  
  22.     $(".rating-wrap-ul").css({  
  23.         "background-position" : "0 -90px"  
  24.     });  
  25. }  
  26. function onLiMouseOver(grade){  
  27.     switch(grade){  
  28.         case 1 : document.getElementById("ratingText").innerHTML="很差";break;  
  29.         case 2 : document.getElementById("ratingText").innerHTML="差";break;  
  30.         case 3 : document.getElementById("ratingText").innerHTML="还行";break;  
  31.         case 4 : document.getElementById("ratingText").innerHTML="好";break;  
  32.         case 5 : document.getElementById("ratingText").innerHTML="很好";break;  
  33.         default :  document.getElementById("ratingText").innerHTML="";  
  34.     }  
  35. }  
  36. function onLiMouseOut(){  
  37.     onLiMouseOver(starValue);  
  38. }  
  39. function clickStar(grade){  
  40.     starValue = grade;        
  41.     var y = -90 + grade * 18;  
  42.     var position = "0 " + y + "px";  
  43.     $(".rating-wrap-ul").css({  
  44.         "background-position" : position  
  45.     });  

这篇关于使用jQuery实现点评星星效果的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/815284

相关文章

如何使用celery进行异步处理和定时任务(django)

《如何使用celery进行异步处理和定时任务(django)》文章介绍了Celery的基本概念、安装方法、如何使用Celery进行异步任务处理以及如何设置定时任务,通过Celery,可以在Web应用中... 目录一、celery的作用二、安装celery三、使用celery 异步执行任务四、使用celery

使用Python绘制蛇年春节祝福艺术图

《使用Python绘制蛇年春节祝福艺术图》:本文主要介绍如何使用Python的Matplotlib库绘制一幅富有创意的“蛇年有福”艺术图,这幅图结合了数字,蛇形,花朵等装饰,需要的可以参考下... 目录1. 绘图的基本概念2. 准备工作3. 实现代码解析3.1 设置绘图画布3.2 绘制数字“2025”3.3

Jsoncpp的安装与使用方式

《Jsoncpp的安装与使用方式》JsonCpp是一个用于解析和生成JSON数据的C++库,它支持解析JSON文件或字符串到C++对象,以及将C++对象序列化回JSON格式,安装JsonCpp可以通过... 目录安装jsoncppJsoncpp的使用Value类构造函数检测保存的数据类型提取数据对json数

python使用watchdog实现文件资源监控

《python使用watchdog实现文件资源监控》watchdog支持跨平台文件资源监控,可以检测指定文件夹下文件及文件夹变动,下面我们来看看Python如何使用watchdog实现文件资源监控吧... python文件监控库watchdogs简介随着Python在各种应用领域中的广泛使用,其生态环境也

el-select下拉选择缓存的实现

《el-select下拉选择缓存的实现》本文主要介绍了在使用el-select实现下拉选择缓存时遇到的问题及解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的... 目录项目场景:问题描述解决方案:项目场景:从左侧列表中选取字段填入右侧下拉多选框,用户可以对右侧

Python中构建终端应用界面利器Blessed模块的使用

《Python中构建终端应用界面利器Blessed模块的使用》Blessed库作为一个轻量级且功能强大的解决方案,开始在开发者中赢得口碑,今天,我们就一起来探索一下它是如何让终端UI开发变得轻松而高... 目录一、安装与配置:简单、快速、无障碍二、基本功能:从彩色文本到动态交互1. 显示基本内容2. 创建链

springboot整合 xxl-job及使用步骤

《springboot整合xxl-job及使用步骤》XXL-JOB是一个分布式任务调度平台,用于解决分布式系统中的任务调度和管理问题,文章详细介绍了XXL-JOB的架构,包括调度中心、执行器和Web... 目录一、xxl-job是什么二、使用步骤1. 下载并运行管理端代码2. 访问管理页面,确认是否启动成功

使用Nginx来共享文件的详细教程

《使用Nginx来共享文件的详细教程》有时我们想共享电脑上的某些文件,一个比较方便的做法是,开一个HTTP服务,指向文件所在的目录,这次我们用nginx来实现这个需求,本文将通过代码示例一步步教你使用... 在本教程中,我们将向您展示如何使用开源 Web 服务器 Nginx 设置文件共享服务器步骤 0 —

Java中switch-case结构的使用方法举例详解

《Java中switch-case结构的使用方法举例详解》:本文主要介绍Java中switch-case结构使用的相关资料,switch-case结构是Java中处理多个分支条件的一种有效方式,它... 目录前言一、switch-case结构的基本语法二、使用示例三、注意事项四、总结前言对于Java初学者

Golang使用minio替代文件系统的实战教程

《Golang使用minio替代文件系统的实战教程》本文讨论项目开发中直接文件系统的限制或不足,接着介绍Minio对象存储的优势,同时给出Golang的实际示例代码,包括初始化客户端、读取minio对... 目录文件系统 vs Minio文件系统不足:对象存储:miniogolang连接Minio配置Min