首页 > 其他分享 >星级评分插件

星级评分插件

时间:2023-04-17 10:37:43浏览次数:71  
标签:插件 square star 评分 ul background 星级 position active


网上看到的一个星级评分插件,觉得写的非常不错,对其原理进行分析。从代码来看最主要的是使用css样式的background-position属性

background-position -20 -20表示背景图向左移动20px、向上移动20px

background-position 20 20表示背景图向右移动20px、向下移动20px

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
*{margin:0;padding:0;list-style-type:none;}
a,img{border:0;}
body{font:12px/180% Arial, Helvetica, sans-serif, "新宋体";}
.starbox{width:480px;margin:20px auto;height:30px;border:0px solid red;}
.s_name{float:left;display:block;width:60px;text-align:right;}
/*定义颗小星星为没有选中的*/
.star_ul{background:url(images/star.png) no-repeat 0 -150px;width:132px;z-index:10;position:relative;height:25px;border:0px solid yellow;}
.star_ul li{float:left;margin-right:1px;width:25px;height:25px;border:0px solid blue;}
.star_ul li a{display:block;height:25px;position:absolute;left:0;top:0;text-indent:-999em;}
/*定义背景图*/
.star_ul li .active-star{background:url(images/star.png) no-repeat;}
/*定义每个背景图的位置*/
.star_ul li .one-star{width:25px;background-position:0 -120px;z-index:50;}/*背景图水平位置不动,垂直位置移动50像素,也就是左边不动向上移动120像素 -120px表示向上移动*/
.star_ul li .two-star{width:51px;background-position:0 -90px;z-index:40;}/*背景图水平位置不动,左边不动向上移动90像素 -90px表示向上移动*/
.star_ul li .three-star{width:79px;background-position:0 -60px;z-index:30;}/*背景图水平位置不动,左边不动向上移动60像素 -60px表示向上移动*/
.star_ul li .four-star{width:105px;background-position:0 -30px;z-index:20;}/*背景图水平位置不动,左边不动向上移动30像素 -30px表示向上移动*/
.star_ul li .five-star{width:129px;margin-right:0;background-position:0 0;z-index:10;}
.s_result{padding:6px 0 0 5px;}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
	var flag = 1;
	
	$('.star_ul a').hover(function(){
		flag = 1;
		$('.star_ul a').removeClass('active-star');
		$(this).addClass('active-star');
		$('.s_result').css('color','#c00').html($(this).attr('title'))
	},function(){
		if( flag == 1){
		$(this).removeClass('active-star');
		$('.s_result').css('color','#333').html('请打分')
		}
	});
	
	$('.star_ul a').click(function(){
		 flag = 2;
		$(this).addClass('active-star');
		$('.s_result').css('color','#c00').html($(this).attr('title'))
		});
	
	$('.square_ul a').hover(function(){
		flag = 3;
		$('.square_ul a').removeClass('active-square');
		$(this).addClass('active-square');
		$(this).parents('.starbox').find('.s_result_square').css('color','#c00').html($(this).attr('title'))
	},function(){
		if(flag == 3){
		$(this).removeClass('active-square');
		$(this).parents('.starbox').find('.s_result_square').css('color','#333').html('请打分')
	}
	});
	
	$('.square_ul a').click(function(){
		flag = 4;
		$(this).addClass('active-square');
		$(this).parents('.starbox').find('.s_result_square').css('color','#c00').html($(this).attr('title'))	});
})
</script>
 </head>
 <body>
<div class="starbox">
	<span class="s_name">总体评价:</span>
	<ul class="star_ul fl">
		<li><a class="one-star" title="很差" href="#"></a></li>
		<li><a class="two-star" title="差" href="#"></a></li>
		<li><a class="three-star" title="还行" href="#"></a></li>
		<li><a class="four-star" title="好" href="#"></a></li>
		<li><a class="five-star" title="很好" href="#"></a></li>
	</ul>
	<span class="s_result fl">请打分</span>
</div>

<div class="starbox">
	<span class="s_name">口味:</span>
	<ul class="square_ul fl">
		<li><a class="square-1" title="差" href="#"></a></li>
		<li><a class="square-2" title="一般" href="#"></a></li>
		<li><a class="square-3" title="好" href="#"></a></li>
		<li><a class="square-4" title="很好" href="#"></a></li>
		<li><a class="square-5" title="非常好" href="#"></a></li>
	</ul>
	<span class="s_result_square fl">请打分</span>
</div>

<div class="starbox">
	<span class="s_name">环境:</span>
	<ul class="square_ul fl">
		<li><a class="square-1" title="差" href="#"></a></li>
		<li><a class="square-2" title="一般" href="#"></a></li>
		<li><a class="square-3" title="好" href="#"></a></li>
		<li><a class="square-4" title="很好" href="#"></a></li>
		<li><a class="square-5" title="非常好" href="#"></a></li>
	</ul>
	<span class="s_result_square fl">请打分</span>
</div>
 </body>
</HTML>

 

标签:插件,square,star,评分,ul,background,星级,position,active
From: https://blog.51cto.com/u_16071779/6194497

相关文章

  • imagesLoaded插件
    imagesLoaded插件是一个在图片加载成功后才做一系列操作官方网站:https://github.com/desandro/imagesloaded/使用语法:$(selector).imagesLoaded([callback]); ImagesLoaded可以呼吁一个元素中的图像,图像直接,或两者的结合。selector选择器支持:1.直接为图片2.内嵌图片3.两......
  • struts2整合convention插件
    <?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEstrutsPUBLIC"-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.1//EN""http://struts.apache.org/dtds/struts-2.1.dtd"><struts><consta......
  • gitee github 左侧栏树形显示插件 Octotree codetree 浏览器插件
    起因看到一位仁兄用gitee做仓库https://gitee.com/zhengqingya/java-developer-document然后左侧栏挺方便(抖音视频)下载chrome扩展市场搜octotree用于githubcodetree用于gitee双核浏览器扩展市场搜octotree用于githubgitcodetree用于gitee......
  • MySQL McAfee审计插件Audit Plugin安装
     MySQLMcAfee审计插件AuditPlugin安装 官网下载:https://github.com/trellix-enterprise/mysql-audit/releases官方文档:https://github.com/trellix-enterprise/mysql-audit/wiki防爬虫:https://www.cnblogs.com/PiscesCanon/p/17324406.html  注意要对应你的数据库软......
  • Dynamic 导入插件解决方案包,提示: Assembly must be registered in isolation 错误
    错误信息如下:<s:Envelopexmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode>s:Client</faultcode><faultstringxml:lang="zh-CN">Actionfailedforassembly'AccountManage,V......
  • Visual Studio Code 常见的配置、常用好用插件以及【vsCode 开发相应项目推荐安装的插
    一、VsCode常见的配置1、取消更新把插件的更新也一起取消了2、设置编码为utf-8:默认就是了,不用设置了3、设置常用的开发字体:Consolas,默认就是了,不用设置了字体对开发也很重要,不同字体,字母形态都不太一样,尤其是标点符号,逗号和分号的区分,有的字体看着这两者就很像......
  • 网页滚动体验,IScroll滚动插件,你安装了类似的滚动页面插件吗
    IScroll是一款基于JavaScript的插件,用于在网页中实现平滑滚动效果。这个插件可以帮助用户创建回到页面顶部和底部的按钮、生成页面导航快照,以及设置滚动时间等功能,从而提升网页的用户体验。IScroll的特点在于,它能够平滑地滚动网页内容,而不会像传统的滚动条那样跳跃。此外,该插件可以......
  • 网页滚动体验,IScroll滚动插件,你安装了类似的滚动页面插件吗
    IScroll是一款基于JavaScript的插件,用于在网页中实现平滑滚动效果。这个插件可以帮助用户创建回到页面顶部和底部的按钮、生成页面导航快照,以及设置滚动时间等功能,从而提升网页的用户体验。IScroll的特点在于,它能够平滑地滚动网页内容,而不会像传统的滚动条那样跳跃。此外,该插......
  • Vue3组合API自动引入插件
    插件名:unplugin-auto-importurl:https://github.com/antfu/unplugin-auto-import安装1、下载插件npmiunplugin-auto-import-D2、配置vite.config.tsimportvuefrom'@vitejs/plugin-vue'import{defineConfig}from'vite'//引入插件,因为我使用的vite+ts,所以这里引......
  • java maven-plugin-shade插件 Maven生成的jar运行出现“没有主清单属性”
    命令窗口运行jar,提示“没有主清单属性”  2.1分析问题在打包构建的jar目录内,可以看到有一个MANIFEST.MF文件,如图所示:该文件就是jar运行时要查找的清单目录,其中主清单数据,就是我们要运行的主类(函数入口main所在的类);提示缺少主清单属性,就是文件中少了主清单属性如下所示:正......