Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the switch button of mobile terminal by vue

Shulou Source: shulou.com Published: 2022-06-01 12:02:50 10月01日 Update

This article mainly explains "how to realize the switch button of the mobile terminal by vue". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to realize the switch button of the mobile terminal by vue".

Logic:

1. Write an oval div

two。 Dynamically change the background color of the oval div

3. Write a dot, which is positioned on the oval div by absolute positioning.

4. When switching back and forth, use translateX to move the position of the dot and dynamically change the background color of the oval div

Code:

Html:

Departmental function {{isShow?' Turn on': 'close'}}

Css:

.department {height: px2rem; background: # ffffff; padding: 0 px2rem (66) 0; margin-top: px2rem (4); display: flex; justify-content: space-between;. Department-l {line-height: px2rem (178); font-size: px2rem (53); ccolor: # 303030;}. Department-r {line-height: px2rem (178); font-size: px2rem (50) Color: # 454545;}} .switch {display: inline-block; width: px2rem; height: px2rem; background: # DBDBDB; border-radius: px2rem; position: relative; vertical-align: middle; margin-left: px2rem (31); .switch-circle {position: absolute; left: px2rem (6); top: px2rem (6); width: px2rem (73) Height: px2rem (73); border-radius: 50%; background: # fff;}} .on {background:-webkit-linear-gradient (left, # 19A89F, # 9CDD97); / * Safari 5.16.0* / background:-o-linear-gradient (right, # 19A89F, # 9CDD97) / * Opera 11.112.0 * / background:-moz-linear-gradient (right, # 19A89F, # 9CDD97); / * Firefox 3.615 * / background: linear-gradient (to right, # 19A89F, # 9CDD97); / * Standard syntax (must be placed last) * /} .right {transform: translateX (px2rem (55))}

Js:

Export default {name: "clientCreate", data () {return {isShow:false}}, created: function () {}, mounted: function () {} Methods: {switchDepartment:function () {this.isShowroomroomthis.isShow },}} at this point, I believe you have a deeper understanding of "how to realize the switch button on the mobile side of vue". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Mobile oval button end dot content dynamic background color learning positioning practical deeper code location interest function practicality practical Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux vpn MySQL Microsoft OPPO Reno