自定义checkbox 样式

客户说给checkbox radio 样式给统一下,之前一直嫌麻烦,今天写了下,记录下顺便,

directive('input',function(){
	return{
		restrict:'E',
		link:function(scope,element,attrs){
			if(attrs.type=="checkbox"){
				$(element).addClass('checkbox');
				$(element).wrap('<div class="checkboxwrap"></div>');
				scope.$watch(function(){return $(element).attr('checked')},function(newVal){
					if(newVal){
						$(element).parent().addClass('checkbox-checked');
					}else{
						$(element).parent().removeClass('checkbox-checked');
					}
				});
				scope.$watch(function(){return $(element).attr('disabled')},function(newVal){
					if(newVal){
						$(element).parent().addClass('checkbox-disabled');
					}else{
						$(element).parent().removeClass('checkbox-disabled');
					}
				})
			}
		}
	}
})
这是css代码
.checkbox{opacity:0.01;filter:alpha(opacity=1);}
.checkboxwrap{width:13px;height:13px;background:url(../../images/cds/checkbox.png) left top no-repeat;}
.checkboxwrap:hover{background-position:0 -13px;}
.checkboxwrap:active{background-position:0 -26px;}
.checkbox-checked{background-position:-13px 0;}
.checkbox-checked:hover{background-position:-13px -13px;}
.checkbox-checked:active{background-position:-13px -26px;}
.checkbox-disabled{background-position:0 -39px;}
.checkbox-disabled:hover{background-position:0 -39px;}
.checkbox-disabled:active{background-position:0 -39px;}

先给加了个checkbox class,给元素设成透明度0.01,看不见但是点击好使,在外边包了层div,给div 加样式,通过监控checkbox的checked和disabled 属性,给外边的div加class,用的是chrome 下checkbox的样式,搞出来跟真的似的,radio同理。

转载于:https://www.cnblogs.com/wssdzf/p/3730457.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值