在UIverse上看到一个checkBox很好看 但是是H5写的,导入到uniapp中点击没有响应,原因就是H5的checkBox和uniapp的checkbox是不一样的。
/* The switch - the box around the slider */
.switch {
font-size: 1rem;
position: relative;
display: inline-block;
width: 4em;
height: 2em;
}
/* Hide default HTML checkbox */
.switch input {
opacity: 0;
width: 0;
height: 0;
}
/* The slider */
.slider {
position: absolute;
cursor: pointer;
inset: 0;
background-color: #eee;
transition: 0.4s;
border-radius: 0.5em;
box-shadow: 0 0.2em #dfd9d9;
}
.slider:before {
position: absolute;
content: "";
height: 1.5em;
width: 1.4em;
border-radius: 0.3em;
left: 0.3em;
bottom: 0.7em;
background-color: lightsalmon;
transition: 0.4s;
box-shadow: 0 0.4em #bcb4b4;
}
.slider:hover::before {
box-shadow: 0 0.2em #bcb4b4;
bottom: 0.5em;
}
input:checked+.slider:before {
transform: translateX(2em);
background: lightgreen;
}
就是这样一个switch按钮
如何才能在uniapp中使用?
原因是uniapp对input标签做了处理,成了内置组件,type不再支持checkbox,样式还有编译后的dom也发生了变化。
详情:https://uniapp.dcloud.net.cn/component/input.html#type
要想要的效果,建议手写一个组件不是input标签,采用view,添加监听事件来实现交互。
望采纳。
这篇对你有帮助:https://ask.dcloud.net.cn/m/question/139475
原因是小程序所使用的标签不一样样式也有点区别,你需要改造一下。可以看一下想做出什么样的效果吗,我瞧瞧