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

Overview of the Differences between Linux TTY/PTS

When we type a letter on the keyboard, how is it ...

Centos7 install mysql5.6.29 shell script

This article shares the shell script of mysql5.6....

HTML+CSS+JS sample code to imitate the brightness adjustment effect of win10

HTML+CSS+JS imitates win10 brightness adjustment ...

Build a severe weather real-time warning system with Node.JS

Table of contents Preface: Step 1: Find the free ...

Solution to the problem of failure to insert emoji expressions into MySQL

Preface I always thought that UTF-8 was a univers...

Detailed troubleshooting of docker.service startup errors

Execute the following command to report an error ...

A brief talk on responsive design

1. What is responsive design? Responsive design i...

DIV background semi-transparent text non-translucent style

DIV background is semi-transparent, but the words ...

Detailed application of Vue dynamic form

Overview There are many form requirements in the ...

Nginx configuration and compatibility with HTTP implementation code analysis

Generate SSL Key and CSR file using OpenSSL To co...

A brief analysis of the responsiveness principle and differences of Vue2.0/3.0

Preface Since vue3.0 was officially launched, man...

Detailed explanation of Java calling ffmpeg to convert video format to flv

Detailed explanation of Java calling ffmpeg to co...

MySQL data insertion optimization method concurrent_insert

When a thread executes a DELAYED statement for a ...

mysql 5.7.5 m15 winx64.zip installation tutorial

How to install and configure mysql-5.7.5-m15-winx...