antd-mobile
Version:
基于 React 的移动设计规范实现
132 lines (114 loc) • 2.32 kB
text/less
@import '../../style/mixins';
@import '../../style/themes/default';
@switchPrefixCls: am-switch;
.@{switchPrefixCls} {
display: inline-block;
vertical-align: middle;
box-sizing: border-box;
position: relative;
cursor: pointer;
align-self: center;
.checkbox {
width: 102px;
height: 62px;
border-radius: 62px;
box-sizing: border-box;
background: #e5e5e5;
z-index: 0;
margin: 0;
padding: 0;
appearance: none;
border: 0;
cursor: pointer;
position: relative;
transition: all 300ms;
&:before {
content: ' ';
position: absolute;
left: 3px;
top: 3px;
width: 96px;
height: 56px;
border-radius: 56px;
box-sizing: border-box;
background: @fill-base;
z-index: 1;
transition: all 200ms;
transform: scale(1);
}
&:after {
content: ' ';
height: 56px;
width: 56px;
border-radius: 56px;
background: @fill-base;
position: absolute;
z-index: 2;
left: 3px;
top: 3px;
transform: translateX(0);
transition: all 200ms;
box-shadow: 4px 4px 8px @color-shadow;
}
&.checkbox-disabled {
z-index: 3;
}
}
input[type="checkbox"] {
position: absolute;
top: 0;
left: 0;
opacity: 0;
width: 100%;
height: 100%;
z-index: 2;
border: 0 none;
appearance: none;
&:checked {
& + .checkbox {
background: @switch-fill;
&:before {
transform: scale(0);
}
&:after {
transform: translateX(40px);
}
}
}
&:disabled {
& + .checkbox {
opacity: @opacity-disabled;
}
}
}
&&-android {
.checkbox {
width: 140px;
height: 44px;
border-radius: @radius-sm;
background: #a7aaa6;
&:before {
display: none;
}
&:after {
width: 67px;
height: 38px;
border-radius: @radius-xs;
box-shadow: none;
}
}
input[type="checkbox"] {
&:checked {
& + .checkbox {
background: @switch-fill-android;
&:before {
transform: scale(0);
}
&:after {
transform: translateX(67px);
}
}
}
}
}
}