如下是学习心得,如何制作一个开关样式。
.hbk-switch{
display: inline-block;
vertical-align: top;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.hbk-switch .hbk-helper{
display: inline-block;
position: relative;
width: 40px;
height: 16px;
border-radius: 8px;
background: rgba(0, 0, 0, 0.26);
transition: background 0.28s cubic-bezier(0.4, 0, 0.2, 1);
vertical-align: middle;
cursor: pointer;
}
.hbk-switch .hbk-helper:before{
content: '';
position: absolute;
top: -4px;
left: -4px;
width: 24px;
height: 24px;
background: #fafafa;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
border-radius: 50%;
webkit-transition: left 0.28s cubic-bezier(0.4, 0, 0.2, 1), background 0.28s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.28s cubic-bezier(0.4, 0, 0.2, 1);
transition: left 0.28s cubic-bezier(0.4, 0, 0.2, 1), background 0.28s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
.hbk-switch input {
position: absolute;
z-index: 1;
width: 46px;
margin: 0 0 0 -4px;
height: 24px;
opacity: 0;
filter: alpha(opacity=0);
cursor: pointer;
}
.hbk-switch input:checked + .hbk-helper:before {
left: 20px;
}
前端放到一个ul标签里
<li id="hbk-width">
<div class="hbk-switch">
<input id="input-switch" type="checkbox" hidden="hidden"/>
<label for="input-switch" class="hbk-helper"></label>
</div>
</li>
效果图如下: