css3 滑动开关按钮 竖着的

18 篇文章 0 订阅
9 篇文章 0 订阅

在网上找了半天没有竖着的滑动开关,自己赶紧写一个

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>switch</title>

		<style>
		.switch{
			width: 24px;
		    height: 46px;
		    background: white;
		    border-radius: 20px;
		    border: 1px solid #CCCCCC;
		    position: relative;
		    background: linear-gradient(180deg,rgba(255,178,178,1) 0%,rgba(255,128,128,1) 100%);
		    box-shadow: 0px 0px 1px rgba(43,131,232,0.2);
			transition: background 1s ; 
		
		}
		.switch-border{
			    width: 18px;
			    height: 18px;
			    border-radius: 50%;
			    background: white;
			    display: inline-block;
			    position: absolute;
			    top: 5px;
			    left: 3px;
				transition: top 1s ; 
				cursor: pointer;
		}
		.switch-on{
			    font-size: 10px;
			    position: absolute;
			    /* top: 0; */
			    display: inline-block;
			    bottom: 5px;
			    left: 50%;
			    width: 24px;
			    margin-left: -12px;
			    text-align: center;
			    color: white;
				transition: bottom 1s ; 
		}
		.switch-bottom{
			bottom: 26px;
		}
		.switch-bg{
			background: linear-gradient(180deg,rgba(230,230,230,1) 0%,rgba(181,181,181,1) 100%);
		}
		.switch-top{
			top:24px
		}

  </style>
	</head>
	<body>
		<div class="switch">
			<span class="switch-border"></span>
			<span class="switch-on">开</span>

		</div>
		<script src="https://libs.baidu.com/jquery/2.1.1/jquery.min.js"></script>
		<script type="text/javascript">
			let status = false
			$(".switch-border").click(function() {
				status = !status
				if (status == true) {
					$(".switch-on").text("关")
				} else {
					$(".switch-on").text("开")
				}
				$(this).toggleClass("switch-top")
				$(".switch-on").toggleClass("switch-bottom")

				$(".switch").toggleClass("switch-bg")

			})
		</script>
	</body>
</html>

直接扣去用

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值