纯CSS3 滑动按钮

1 篇文章 0 订阅
<style>
			.onoffswitch {position: absolute;right: 15px;top: 50%;margin-top: -15px; width:50px;-webkit-user-select: none;-moz-user-select: none;-ms-user-select: none;}
			.onoffswitch-checkbox {display: none;}
			.onoffswitch-label {display: block;overflow: hidden;cursor: pointer;border-radius: 20px;}
			.onoffswitch-inner {display: block;width: 200%;margin-left: -100%;transition: margin 0.3s ease-in 0s;}
			.onoffswitch-inner:before,.onoffswitch-inner:after{display: block;float: left;width: 50%;height: 30px;padding: 0;line-height: 30px;font-size: 19px;color: white;font-family: Trebuchet, Arial, sans-serif;font-weight: bold;box-sizing: border-box;}
			.onoffswitch-inner:before {content: "";padding-left: 13px;background-color: #a82d6f;}
			.onoffswitch-inner:after {content: "";padding-right: 13px;background-color: #999;text-align: right;}
			.onoffswitch-switch {display: block;width: 28px;height: 28px; margin:1px;background: #FFFFFF;position: absolute;top: 0;bottom: 0;right: 20px;border-radius: 20px;transition: all 0.3s ease-in 0s;}
			.onoffswitch-checkbox:checked+.onoffswitch-label .onoffswitch-inner {margin-left: 0;}
			.onoffswitch-checkbox:checked+.onoffswitch-label .onoffswitch-switch {right: 0px;}
		</style>
		<div class="onoffswitch">
					<input type="checkbox" name="onoffswitch" checked class="onoffswitch-checkbox" id="myonoffswitch" >
					<label class="onoffswitch-label" for="myonoffswitch">
					 <span class="onoffswitch-inner"></span>
					 <span class="onoffswitch-switch"></span>
					</label>
			</div>
			<script>
			$(".onoffswitch-label").click(function(){	
					var ac =$(".onoffswitch-checkbox[type='checkbox']");
					layer.confirm('您是如何看待前端开发?', {
						  btn: ['重要','奇葩'] //按钮
						}, function(){
						  layer.msg('的确很重要', {icon: 1});
						}, function(){
						  console.log(4);
		          if(ac.is(":checked")){
				    		ac.prop("checked",false);
				    	}else{
				        ac.prop("checked",true);
				      }
						});
		    });

所以有个经验就是:

  • 对于HTML元素本身就带有的固有属性,在处理时,使用prop方法。快速,准确。

  • 对于HTML元素我们自己自定义的DOM属性,在处理时,使用attr方法。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

YaoZhanHui

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值