Vue component to realize carousel animation

Vue component to realize carousel animation

This article example shares the specific code of Vue component to realize carousel animation for your reference. The specific content is as follows

The source code is as follows

<template>
  <div id="wrapper">
    <transition-group name="list" tag="ul" mode="out-in">
      <li v-for="(item,index) in piclist" :key="item.url" :style="config[index]">
        <img :src="item.url">
      </li>
    </transition-group>
    <a href="javascript:;" id="arrLeft" class="prev" @click="turnleft"></a>
    <a href="javascript:;" id="arrRight" class="next" @click="turnright"></a>
  </div>
</template>

js:

export default {
  data() {
    return {
      piclist: [
        { url: require("../image/pic1.png") },
        { url: require("../image/pic2.png") },
        { url: require("../image/pic3.png") }
      ],
      //File image configuration config: [
        {
          position: "absolute",
          width: "400px",
          top: "20px",
          left: "50px",
          opacity: 0.2,
          zIndex: 2,
          transition: "1s"
        },
        {
          position: "absolute",
          width: "800px",
          top: "100px",
          left: "200px",
          opacity: 1,
          zIndex: 4,
          transition: "1s"
        },
        {
          position: "absolute",
          width: "400px",
          top: "20px",
          left: "750px",
          opacity: 0.2,
          zIndex: 2,
          transition: "1s"
        }
      ],
      previous: 0,
      now: Date.now()
    };
  },
  methods: {
  //Realize the animation of clicking the button to switch, set the time parameter to prevent multiple clicks turnleft: function() {
      this.now = Date.now();
      if (this.now - this.previous > 1000) {
        this.config.push(this.config.shift());
        this.previous = this.now;
      }
    },
    turnright: function() {
      this.now = Date.now();
      if (this.now - this.previous > 1000) {
        this.config.unshift(this.config.pop());
        this.previous = this.now;
      }
    }
  }
};

css:

* {
  margin: 0;
  padding: 0;
}
#wrapper {
  margin: auto;
  height: 500px;
  width: 79%;
  position: relative;
}
ul {
  list-style: none;
}
li img {
  height: 500px;
  width: 100%;
}
.prev,
.next {
  position: absolute;
  height: 60px;
  width: 60px;
  border-radius: 50%;
  top: 50%;
  margin-top: -56px;
  overflow: hidden;
  text-decoration: none;
  background-color: aqua;
  z-index: 5;
  opacity: 1;
}
.prev {
  left: 0;
}
.next {
  right: 0;
}
.picleft {
  width: 400;
  top: 20;
  left: 50;
  opacity: 0.2;
  z-index: 2;
}
.piccenter {
  width: 800;
  top: 100;
  left: 200;
  opacity: 1;
  z-index: 4;
}
.picright {
  width: 400;
  top: 20;
  left: 750;
  opacity: 0.2;
  z-index: 2;
}

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:
  • Vue implements carousel animation
  • Realizing carousel animation effect based on Vue3

<<:  How to create a database in navicat 8 for mysql

>>:  How to automatically backup the script for Linux servers (mysql, attachment backup)

Recommend

js returns to the previous page and refreshes the code

1. Javascript returns to the previous page history...

4 solutions to CSS browser compatibility issues

Front-end is a tough job, not only because techno...

Implementation of grayscale release with Nginx and Lua

Install memcached yum install -y memcached #Start...

mysql5.7.19 winx64 decompressed version installation and configuration tutorial

Recorded the installation tutorial of mysql 5.7.1...

Navicat multiple ways to modify MySQL database password

Method 1: Use the SET PASSWORD command First log ...

The whole process of developing a Google plug-in with vue+element

Simple function: Click the plug-in icon in the up...

How to prompt and open hyperlink a

<br />The countless information on the Inter...

W3C Tutorial (16): Other W3C Activities

This section provides an overview of some other i...

Implementation of dynamic particle background plugin for Vue login page

Table of contents The dynamic particle effects ar...

nginx+tomcat example of accessing the project through the domain name

I was curious about how to access the project usi...

Deployment and configuration of Apache service under Linux

Table of contents 1 The role of Apache 2 Apache I...

A Deeper Look at the Differences Between Link and @import

There are three main ways to use CSS in a page: ad...