微信小程序switch組件使用詳解
本文實(shí)例為大家分享了微信小程序switch組件的實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下
效果圖

HTML
<div class="switch-list"> <span class="fui-fr">紅色switch組件</span> <input class="fui-switch" style="color:rgb(255, 0, 0);" type="checkbox" checked> </div> <div class="switch-list"> <span class="fui-fr">綠色switch組件</span> <input class="fui-switch" style="color:rgb(76, 216, 100);" type="checkbox" checked> </div> <div class="switch-list"> <span class="fui-fr">綠色禁用switch組件</span> <input class="fui-switch" style="color:rgb(76, 216, 100);" type="checkbox" checked disabled> </div> <div class="switch-list"> <span class="fui-fr">藍(lán)色switch組件---開(kāi)</span> <input class="fui-switch" style="color:blue" type="checkbox" checked> </div> <div class="switch-list"> <span class="fui-fr">藍(lán)色switch組件---關(guān)</span> <input class="fui-switch" style="color:blue" type="checkbox"> </div>
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;}
實(shí)現(xiàn)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 設(shè)計(jì)圖代表 100px ;
switch 的切換動(dòng)畫(huà)是通過(guò) CSS3 的 transition 屬性實(shí)現(xiàn);
主要是控制 switch 的 after 的移動(dòng),以及 before 的放大縮小動(dòng)畫(huà)。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JS實(shí)現(xiàn)文字向下滾動(dòng)完整實(shí)例
這篇文章主要介紹了JS實(shí)現(xiàn)文字向下滾動(dòng)的方法,以一個(gè)完整實(shí)例形式詳細(xì)分析了html頁(yè)面布局、css樣式及對(duì)應(yīng)的js滾動(dòng)功能實(shí)現(xiàn)技巧,需要的朋友可以參考下2015-02-02
微信小程序使用this.setData()遇到的問(wèn)題及解決方案詳解
this.setData估計(jì)是小程序中最經(jīng)常用到的一個(gè)方法,但是要注意其實(shí)他是有限制的,忽略這些限制的話,會(huì)導(dǎo)致數(shù)據(jù)無(wú)法更新,下面這篇文章主要給大家介紹了關(guān)于微信小程序使用this.setData()遇到的問(wèn)題及解決方案,需要的朋友可以參考下2022-08-08
ES6 Symbol在對(duì)象中的作用實(shí)例分析
這篇文章主要介紹了ES6 Symbol在對(duì)象中的作用,結(jié)合實(shí)例形式分析了ES6 Symbol在對(duì)象中聲明、使用方法與相關(guān)注意事項(xiàng),需要的朋友可以參考下2020-06-06
微信小程序使用navigator實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)功能
本周學(xué)習(xí)了navigtor到導(dǎo)航組件,目前我想使用navigtor組件實(shí)現(xiàn)跳轉(zhuǎn)以及返回功能,下面這篇文章主要給大家介紹了關(guān)于微信小程序使用navigator實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)功能的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08

