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

CSS to achieve glowing text and a little bit of JS special effects

Implementation ideas: Use text-shadow in CSS to a...

How to create your first React page

Table of contents What is Rract? background React...

The best way to solve the 1px border on mobile devices (recommended)

When developing for mobile devices, you often enc...

You Probably Don’t Need to Use Switch Statements in JavaScript

Table of contents No switch, no complex code bloc...

CSS3 uses the transition property to achieve transition effects

Detailed description of properties The purpose of...

61 Things Every Web Developer Should Know

Normally, you'll need to read everyone's s...

Detailed tutorial on installation and configuration of nginx under Centos7

Note: The basic directory path for software insta...

Introduction to new features of MySQL 8.0.11

MySQL 8.0 for Windows v8.0.11 official free versi...

Markup Language - Image Replacement

Click here to return to the 123WORDPRESS.COM HTML ...

Detailed steps to build an NFS file sharing server in Linux

Linux builds NFS server In order to achieve data ...

JavaScript to achieve tab switching effect

This article shares the specific code of JavaScri...

Detailed tutorial on installing Docker on CentOS 8

1. Previous versions yum remove docker docker-cli...