This article example shares the specific code of native JS encapsulation vue Tab switching for your reference. The specific content is as follows First look at the effect pictureTechnology usedvue,js,css3 Vue components can be used directly <template> <div class="bookcircle-header"> <ul class="wrapper" :class="headerActive == 0 ? 'friend' : 'booklist'"> <li @click="headerChange(0)" :class="headerActive == 0 ? 'active' : ''"> Book Friends</li> <li @click="headerChange(1)" :class="headerActive == 1 ? 'active' : ''"> Book list</li> </ul> </div> </template> <script> export default { components: {}, data() { return { headerActive: 0, }; }, computed: {}, created() {}, mounted() { //Initialize the send this.$emit("change", this.headerActive); }, methods: { headerChange(index) { this.headerActive = index; this.$emit("change", index); }, }, }; </script> <style lang="less" scoped> .bookcircle-header { height: 42px; display: flex; justify-content: center; align-items: center; .wrapper { width: 286px; font-size: 14px; height: 29px; color: #1489fe; border: 1px solid #1489fe; border-radius: 14px; display: flex; justify-content: center; align-items: center; position: relative; box-sizing: border-box; // Solve border overflow and include border inside the box li { flex: 1; height: 100%; display: flex; justify-content: center; align-items: center; z-index: 2; } .active { color: white; } &::before { content: ""; width: 143px; height: 100%; background-color: #1489fe; position: absolute; top: 0px; left: 0px; border-radius: 13px 0px 0px 13px; z-index: 1; transition: all 0.3s; } &.firend::before { transform: translateX(0); border-radius: 13px 0px 0px 13px; } &.booklist::before { transform: translateX(100%); border-radius: 0px 13px 13px 0px; } } } </style> Implementation principle:Use ul, li and flexible box. First, set the width and height of the parent element. Then use the flexible box to expand the child element li horizontally. Set flex: 1 for the child element li to make the child element share the width of the parent element. Then set a pseudo-element for the parent element to cover the first li element in an absolutely positioned manner, and use the z-index attribute to control the hierarchical display relationship between the pseudo-element and the child element. Then set the transition attribute on the pseudo element and use the transform: translateX(); attribute to move the element horizontally. Note: 1. Although the click event of the switch is on the child element and the active style is added to the child element, the switching effect of the tab is not achieved through the child element, but through the pseudo-element of the parent element. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: How to configure mysql on ubuntu server and implement remote connection
>>: VMware Workstation is not compatible with Device/Credential Guard
Blank's blog: http://www.planabc.net/ The use...
This article example shares the specific code of ...
Table of contents introduce Prepare Download syst...
This article shares the specific code for WeChat ...
This article example shares the specific code of ...
Table of contents Preface 1. Basic knowledge of d...
Simple description Since it was built with Centos...
General mobile phone style: @media all and (orien...
1. Linux kernel driver module mechanism Static lo...
Phenomenon The system could compile the Linux sys...
Problem explanation: When using the CSS animation...
I wrote this blog to remember that I just install...
Record the problem points of MySQL production. Bu...
This article shares with you how to use Vue to ch...
The database installation tutorial of MySQL-8.0.2...