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
There are too much knowledge to learn recently, a...
Preface Recently, I encountered a requirement. Du...
1. Create a new object using the Object.create() ...
Table of contents 1. Merge arrays 2. Merge arrays...
Recently, I encountered many problems when instal...
Description of the problem: When the number of as...
Add table fields alter table table1 add transacto...
front end css3,filter can not only achieve the gr...
Recently, when I was learning how to use webpack,...
Recently, the Vue project needs to refresh the da...
This article uses the "Attribution 4.0 Inter...
1. Go to the location where you want to store the...
1. Tools directory file structure [root@www tools...
Preface Regarding the use of MySQL indexes, we ha...
The development of Docker technology provides a m...