Detailed explanation of the use of Vue card-style click-to-switch image component

Detailed explanation of the use of Vue card-style click-to-switch image component

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)">&lt;</div>
    <div class="arrow-right" @click="toggleFun(1)">&gt;</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:
  • How to implement the Vue mouse wheel scrolling switching routing effect
  • Vue implements scrolling the mouse wheel to switch pages
  • Vue uses swiper to switch pictures by sliding left and right
  • Vue implements button switching picture
  • Vue custom js picture fragment carousel switching effect implementation code
  • Vue realizes picture switching effect
  • Vue implements switching function between base64 encoded images
  • Vue implements simple image switching effect
  • Vue+js click arrow to switch pictures
  • Vue implements mouse hover to switch image src

<<:  Example of how to implement master-slave hot standby using Docker+keepalived+nginx

>>:  Detailed explanation of MySQL covering index

Recommend

Steps to run ASP.NET Core in Docker container

There are too much knowledge to learn recently, a...

Detailed explanation of Object.create instance usage in js

1. Create a new object using the Object.create() ...

JavaScript Shorthand Tips

Table of contents 1. Merge arrays 2. Merge arrays...

Problems with installing mysql and mysql.sock under linux

Recently, I encountered many problems when instal...

Mysql SQL statement operation to add or modify primary key

Add table fields alter table table1 add transacto...

CSS3 filter code to achieve gray or black mode on web pages

front end css3,filter can not only achieve the gr...

How to debug loader plugin in webpack project

Recently, when I was learning how to use webpack,...

Real-time refresh of long connection on Vue+WebSocket page

Recently, the Vue project needs to refresh the da...

Tutorial on using Docker Compose to build Confluence

This article uses the "Attribution 4.0 Inter...

Detailed steps to install MySQL 5.7 via YUM on CentOS7

1. Go to the location where you want to store the...

Linux uses shell scripts to regularly delete historical log files

1. Tools directory file structure [root@www tools...

Discussion on more reasonable creation rules for MySQL string indexes

Preface Regarding the use of MySQL indexes, we ha...

How to deploy SpringBoot project using Docker

The development of Docker technology provides a m...