最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

在微信小程序中如何使用switch组件

来源:懂视网 责编:小OO 时间:2020-11-27 19:39:15
文档

在微信小程序中如何使用switch组件

本文实例为大家分享了微信小程序switch组件的实现代码,供大家参考,具体内容如下:效果图;HTML;<;p class=";switch-list";>;<;span class=";fui-fr";>;红色switch组件<;/span>;<;input class=";fui-switch";style=";color:rgb(255.0.0);";type=";checkbox";checked>;<;/p>;<;p class=";switch-list";>;<;span class=";>;<。
推荐度:
导读本文实例为大家分享了微信小程序switch组件的实现代码,供大家参考,具体内容如下:效果图;HTML;<;p class=";switch-list";>;<;span class=";fui-fr";>;红色switch组件<;/span>;<;input class=";fui-switch";style=";color:rgb(255.0.0);";type=";checkbox";checked>;<;/p>;<;p class=";switch-list";>;<;span class=";>;<。
这篇文章主要为大家详细介绍了微信小程序switch组件的实现方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

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

效果图

switch组件实现

HTML

<p class="switch-list">
 <span class="fui-fr">红色switch组件</span>
 <input class="fui-switch" style="color:rgb(255, 0, 0);" type="checkbox" checked>
</p>
<p class="switch-list">
 <span class="fui-fr">绿色switch组件</span>
 <input class="fui-switch" style="color:rgb(76, 216, 100);" type="checkbox" checked>
</p>
<p class="switch-list">
 <span class="fui-fr">绿色禁用switch组件</span>
 <input class="fui-switch" style="color:rgb(76, 216, 100);" type="checkbox" checked disabled>
</p>
<p class="switch-list">
 <span class="fui-fr">蓝色switch组件---开</span> 
 <input class="fui-switch" style="color:blue" type="checkbox" checked>
</p>
<p class="switch-list">
 <span class="fui-fr">蓝色switch组件---关</span> 
 <input class="fui-switch" style="color:blue" type="checkbox">
</p>

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,0,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

(function(win,factory){
 factory(win);
 window.addEventListener('resize',function(){factory(win)},false);
}(window,function(win){
 var width = document.documentElement.clientWidth;
 width = width > 750 ? 750 : width;
 document.documentElement.style.fontSize = width / 7.5 + 'px';
}));

注意

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

上面是我整理给大家的,希望今后会对大家有帮助。

相关文章:

在JS/jQuery中如何实现DIV延时几秒后消失或显示

使用原生js实现省市区三级联动

使用vue基础创建增删改查

文档

在微信小程序中如何使用switch组件

本文实例为大家分享了微信小程序switch组件的实现代码,供大家参考,具体内容如下:效果图;HTML;<;p class=";switch-list";>;<;span class=";fui-fr";>;红色switch组件<;/span>;<;input class=";fui-switch";style=";color:rgb(255.0.0);";type=";checkbox";checked>;<;/p>;<;p class=";switch-list";>;<;span class=";>;<。
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top