开关按钮


效果图:


代码:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.div1{
   width: 75px;
   height: 27px;
   line-height: 30px;
   border-radius: 5px;
   overflow: hidden;
   position: relative;
   background: #82e497;
   box-shadow: #82e497 0px 0px 0px 2px;
   color: #fff;
   font-size: 13px;
   margin:30px;
}
.div1 .left{
   position: absolute;
   left:4px;
}
.div1 .right{
   position: absolute;
   right:4px;
}
.div2{
   width: 40px;
   height: 27px;
   border-radius: 14%;
   background: #fff;
   position: absolute;
}
.open1{
   background: #f7ca99;
   box-shadow: #f7ca99 0px 0px 0px 2px;
   text-align: left;
}
.open2{
   top: 0;
   right: 0;
}
.close1{
   background: #82e497;
   box-shadow: #82e497 0px 0px 0px 2px;
   border-left: transparent;
   text-align: right;
}
.close2{
   left: 0px;
   top: 0px;
}
</style>
</head>
<body>


<div class="div1 open1">
<span class="left">隐藏</span>
<span class="right">显示</span>
<div class="div2 open2"></div>
</div>
<div class="div1 open1">
<span class="left">隐藏</span>
<span class="right">显示</span>
<div class="div2 open2"></div>
</div>


    <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>  
<script>
$(".div2").on('click',function(){


       $(this).parent().toggleClass('close1');
       $(this).parent().toggleClass('open1');
       $(this).toggleClass('close2');
       $(this).toggleClass('open2');
})


</script>


</body>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值