一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

jquery星级评分实现代码

时间:2011-12-28 编辑:简简单单 来源:一聚教程网

很多网站都有类似的效果,实现原理也很简单.

html

 代码如下 复制代码


 
 
 
 
 

css

 代码如下 复制代码
.p_rate{height:14px;position:relative;width:80px;overflow:hidden;display:inline-block;background:url(http://www.nolure.com/wp-content/uploads/2011/12/rate.png) repeat-x}
.p_rate i{position:absolute;top:0;left:0;cursor:pointer;height:14px;width:16px;background:url(http://www.nolure.com/wp-content/uploads/2011/12/rate.png) repeat-x 0 -500px}
.p_rate .select{background-position:0 -32px}
.p_rate .hover{background-position:0 -16px}

 

javascript

 代码如下 复制代码
/*
 * 通用打分组件
 * callBack打分后执行的回调
 * this.Index:获取当前选中值
 */
var pRate = function(box,callBack){
 this.Index = null;
 var B = $("#"+box),
  rate = B.children("i"),
  w = rate.width(),
  n = rate.length,
  me = this;
 for(var i=0;i   rate.eq(i).css({
   'width':w*(i+1),
   'z-index':n-i
  });
 }
 rate.hover(function(){
  var S = B.children("i.select");
  $(this).addClass("hover").siblings().removeClass("hover");
  if($(this).index()>S.index()){
   S.addClass("hover");
  }
 },function(){
  rate.removeClass("hover");
 })
 rate.click(function(){
  rate.removeClass("select hover");
  $(this).addClass("select");
  me.Index = $(this).index() + 1;
  if(callBack){callBack();}
 })
}

完整实例

 代码如下 复制代码


 


jquery星级评论打分组件-nolure的博客,前端开发专业博客,前端学习资源分享








jquery星级评论打分组件

 
 
 
 
 
 
 

 



热门栏目