jQuery实现星星点赞功能

test.html

<!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" />
<title>无标题文档</title>
<script src="startpic/jquery.js"></script>
<link href="startpic/startcss.css" rel="stylesheet" type="text/css" />
</head>
<body>
<script type="text/javascript">
$.fn.studyplay_star=function(options,callback){
	//默认设置
	var settings ={
		MaxStar      :20,
		StarWidth    :23,
		CurrentStar  :5,
		Enabled      :true
		};	
	if(options) { jQuery.extend(settings, options); };
	var container = jQuery(this);
	container.css({"position":"relative"})
	.html('<ul class="studyplay_starBg"></ul>')	
	.find('.studyplay_starBg').width(settings.MaxStar*settings.StarWidth)
	.html('<li class="studyplay_starovering" style="width:'+settings.CurrentStar*settings.StarWidth+'px; z-index:0;" id="studyplay_current"></li>');
	if(settings.Enabled)
	{
	var ListArray = "";	
	for(k=1;k<settings.MaxStar+1;k++)
	{
		ListArray +='<li class="studyplay_starON" style="width:'+settings.StarWidth*k+'px;z-index:'+(settings.MaxStar-k+1)+';"></li>';
	}
	container.find('.studyplay_starBg').append(ListArray)
	container.find('.studyplay_starON').hover(function(){											  
											  $(this).removeClass('studyplay_starON').addClass("studyplay_starovering");
											  $("#studyplay_current").hide();
											  },
									  function(){
										  $(this).removeClass('studyplay_starovering').addClass("studyplay_starON");
										  $("#studyplay_current").show();
										  })
	.click(function(){
					var studyplay_count = settings.MaxStar - $(this).css("z-index")+1;
					$("#studyplay_current").width(studyplay_count*settings.StarWidth)
					//回调函数
					if (typeof callback == 'function') {
					callback(studyplay_count);
					return ;
					}
					})
 }	
}	
</script>
<script type="text/javascript">
		$(document).ready(function(){
			$("#z").studyplay_star({MaxStar:12,CurrentStar:2,Enabled:true},function(value){alert(value)});
		});	
</script>

<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div id="z"></div>
</body>
</html>

startcss.css

@charset "utf-8";
/* CSS Document */

.studyplay_starBg{
	 background:url(start.gif) 0 -22px;position:absolute; top:0; left:0; height:22px; padding:0px; cursor:pointer;
	}
.studyplay_starovering{
	background:url(start.gif); height:22px; position:absolute; top:0; left:0;
}
.studyplay_starON{
	 position:absolute; top:0; left:0; height:22px;
}

在加上js文件和一个gif图
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值