微信小程序switch组件使用详解

本文实例为大家分享微信小程序switch组件的实现代码,供大家参考,具体内容如下

效果

switch组件实现

HTML

rush:xhtml;">
Box">

CSS

rush:css;"> .switch-list{ padding: .5rem; } .fui-switch{ position: relative; width: .87rem; height: .5rem; z-index: 10; display: inline-block; outline: medium; border: 1px solid #dfdfdf; border-radius: .25rem; background-color: #dfdfdf; -webkit-appearance: none; -moz-appearance: none; vertical-align: middle; } .fui-switch:checked{ border-color: currentColor; background-color: currentColor; } .fui-switch::after,.fui-switch::before{ content: ""; position: absolute; height: .44rem; top: 0; left: 0; border-radius: .25rem; -webkit-transition: -webkit-transform .3s; transition: -webkit-transform .3s; transition: transform .3s; transition: transform .3s,-webkit-transform .3s; } .fui-switch:before { width: .84rem; background-color: #fdfdfd; } .fui-switch:checked:before { -webkit-transform: scale(0); transform: scale(0); } .fui-switch:after { width: .44rem; background-color: #fff; Box-shadow: 0 1px 3px rgba(0,.4); } .fui-switch:checked:after { -webkit-transform: translateX(.4rem); transform: translateX(.4rem); } .fui-switch[disabled] { opacity: .5; } .fui-fr{font-size: .3rem;vertical-align: middle;}

实现rem的JS

750 ? 750 : width; document.documentElement.style.fontSize = width / 7.5 + 'px'; }));

注意

此处 1rem 在 750 的 psd 设计图代表 100px ; switch 的切换动画是通过 CSS3 的 transition 属性实现; 主要是控制 switch 的 after 的移动,以及 before 的放大缩小动画。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。

相关文章

开发微信小程序的用户授权登录功能
小程序开发页面如何实现跳转?
浅谈小程序开发中蓝牙连接错误分析及解决方法
什么是小程序?它有哪些功能?
如何配置小程序开发项目结构?(教程)
怎么把自己的店加入小程序