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
CSS3Please Take a look at this website yourself, ...
Will mysql's IN invalidate the index? Won'...
I often need to change nginx configuration at wor...
Table of contents Preface Main implementation cod...
When talking about the screen reading software op...
Table of contents Create a table View the databas...
If an index contains (or covers) the values of ...
Problem description: After the front-end deletes ...
introduce This article is based on React + antd t...
Preface Recently, during an interview, I was aske...
This article shares the specific code of JavaScri...
Table of contents Preface The need for online XML...
Overview The project was created successfully and...
This article mainly introduces how to integrate T...
Find the containerID of tomcat and enter the toma...