WeChat applet switch component usage details, switch Usage Details

Source: Internet
Author: User

Usage of the switch component of the Applet

The example in this article shares the implementation code of the switch component of the applet for your reference. The specific content is as follows:

HTML

<Div class = "switch-list"> <span class = "fui-fr"> red switch component </span> <input class = "fui-switch" style = "color: rgb (255, 0, 0 ); "type =" checkbox "checked> </div> <div class =" switch-list "> <span class =" fui-fr "> green switch component </span> <input class = "fui-switch" style = "color: rgb (1, 76,216,100 ); "type =" checkbox "checked> </div> <div class =" switch-list "> <span class =" fui-fr "> disable the switch component in green </span> <input class = "fui-switch" style = "color: rgb (1, 76,216,100 ); "type =" checkbox "checked disabled> </div> <div class =" switch-list "> <span class =" fui-fr "> Blue switch component --- Open </ span> <input class = "fui-switch" style = "color: blue "type =" checkbox "checked> </div> <div class =" switch-list "> <span class =" fui-fr "> blue switch component --- off </ 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;}

Implement 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';}));

Note:

Here the psd design of 1rem in 750 represents 100px;
The switch switching animation is implemented through the transition attribute of CSS3;
It mainly controls the movement of the switch after and the before zoom-in and zoom-out animation.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.