This article shares the vue card-style click-to-switch image component for your reference. The specific content is as follows Because of the company's business problems, I've been writing a Vue project recently. There is a need for clicking on a card image, but I don't want to write animation effects. So I'm lazy and use the data-driven principle of Vue to write an incomplete Vue component. For simplicity, let's just go straight to the code. Full code No props parameter setting is performed, which will be improved later (simple is best) <template> <!-- *Data-driven card-style display of images (no animation) * --> <div class="cardBanner"> <ul> <li v-for="(item,index) in cardData" :key="index"> <a href="#"> <img :src="item.src" alt=""> <p>Description of this image {{item.order}}</p> </a> </li> <div class="arrow-left" @click="toggleFun(-1)"><</div> <div class="arrow-right" @click="toggleFun(1)">></div> </ul> </div> </template> <script> export default { data(){ return { cardData: [ {id:1,src:require('../assets/images/banner.jpg'),}, {id:2,src:require('../assets/images/text.jpg')}, {id:3,src:require('../assets/images/[email protected]')}, {id:4,src:require('../assets/images/text.jpg')}, {id:5,src:require('../assets/images/banner.jpg')} ] } }, methods: { //Change data through function to achieve view change toggleFun(p){ this.cardData = this.cardData.map((item,index,array) => { if(index===array.length-1&&p===1){ item = array[0] } else if(index===0&&p===-1){ item = array[array.length-1]; }else{ item = array[index+p]; } return item; }) } } } </script> <style scoped> .cardBanner{ padding: 10px 30px; background-color: #fff; border: 1px solid #ccc; position: relative; } .cardBanner ul{ display: flex; overflow: scroll; /*Set scroll bar*/ } .cardBanner ul::-webkit-scrollbar{ /*Hide scroll bar*/ display: none; } .cardBanner ul>li{ //High-energy part, flex is not easy to explain width: 31.33333%; flex-shrink: 0; padding-left: 3%; text-align: center; } .cardBanner ul>li:first-child{ padding-left: 0; } .cardBanner ul>li a{ display: block; width: 100%; height: 100%; } .cardBanner ul>li img{ width: 100%; height: 170px; border-radius: 5px; } .cardBanner ul>li p{ margin: 0; } [class^='arrow']{ font-size: 30px; transform: scaleX(.7); color: #ddd; } .arrow-left{ position: absolute; left: 5px; top: 50%; margin-top: -17px; } .arrow-right position: absolute; right: 5px; top: 50%; margin-top: -17px; } </style> Effect display Let me talk a little bit about it. Use flex!!! 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:
|
<<: Example of how to implement master-slave hot standby using Docker+keepalived+nginx
>>: Detailed explanation of MySQL covering index
When we type a letter on the keyboard, how is it ...
This article shares the shell script of mysql5.6....
HTML+CSS+JS imitates win10 brightness adjustment ...
Table of contents Preface: Step 1: Find the free ...
Preface I always thought that UTF-8 was a univers...
Execute the following command to report an error ...
1. What is responsive design? Responsive design i...
DIV background is semi-transparent, but the words ...
Overview There are many form requirements in the ...
Generate SSL Key and CSR file using OpenSSL To co...
This article uses an example to describe the mana...
Preface Since vue3.0 was officially launched, man...
Detailed explanation of Java calling ffmpeg to co...
When a thread executes a DELAYED statement for a ...
How to install and configure mysql-5.7.5-m15-winx...