首先,我所制作的开关效果是要放置于用 AppCan 制作的 App 中
效果图
Html代码:
<div class="" data-control="BOX" id="Box_points_switch">
<label><input class="mui-switch mui-switch-anim" type="checkbox" id="switch"></label>
</div>
CSS代码:
/*switch开关*/
.mui-switch {
width: 5em;
height: 3.2em;
position: relative;
border: 1px solid #dfdfdf;
background-color: #fdfdfd;
box-shadow: #dfdfdf 0 0 0 0 inset;
border-radius: 3em;
background-clip: content-box;
display: inline-block;
-webkit-appearance: none;
user-select: none;
outline: none;
}
.mui-switch:before {
content: '';
width: 3em;
height: 3em;
position: absolute;
top: 0px;
left: 0;
border-radius: 3em;
background-color: #fff;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.mui-switch:checked:before {
left: 2em;
}
.mui-switch.mui-switch-anim {
transition: border cubic-bezier(0, 0, 0, 1) 0.4s, box-shadow cubic-bezier(0, 0, 0, 1) 0.4s;
}
.mui-switch.mui-switch-anim:before {
transition: left 0.3s;
}
.mui-switch.mui-switch-anim:checked {
box-shadow: #64bd63 0 0 0 16px inset;
background-color: #64bd63;
transition: border ease 0.4s, box-shadow ease 0.4s, background-color ease 1.2s;
}
.mui-switch.mui-switch-anim:checked:before {
transition: left 0.3s;
}
最后是js文件,点击开关事件
$("#switch").change(function() {
if ($("input[type='checkbox']").is(':checked') == true) {
alert("ON");
} else {
alert("OFF");
}
});