This article shares the specific code of Vue to achieve seamless carousel effect for your reference. The specific content is as follows Code 1. Subcomponent code The code is as follows (example): <template> <div> <div class="box" @mouseenter="mouse" @mouseleave="mouseleave"> <ul class="box1"> <li> <img :src="n" v-for="(n, i) in imgs" :key="i" alt="" :style="{ left: (i - index) * 500 + 'px' }" :class="hasAni ? 'animaton' : ''" /> </li> </ul> <p class="tt" @click="left"><</p> <p class="tt1" @click="right">></p> </div> </div> </template> The script code is as follows (example): <script> export default { name: "Lunbo", props: ["imgs"], data() { return { // To use images in js, you need to use require to import index: 1, hasAni: true, istrue: true, }; }, methods: { mouse() { clearInterval(this.timer); }, mouseleave() { this.timer = setInterval(() => { this.index++; this.hasAni = true; if (this.index == this.imgs.length - 1) { setTimeout(() => { this.index = 0; this.hasAni = false; }, 750); } }, 1500); }, right() { if (this.istrue) { this.index++; this.hasAni = true; this.istrue = false; if (this.index == this.imgs.length - 1) { setTimeout(() => { this.index = 1; this.hasAni = false; }, 750); } setTimeout(() => { this.istrue = true; }, 1000); } }, left() { if (this.istrue) { this.index--; this.hasAni = true; this.istrue = false; if (this.index == 0) { setTimeout(() => { this.index = this.imgs.length - 1; this.hasAni = false; }, 750); } setTimeout(() => { this.istrue = true; }, 1000); } }, }, activated() { console.log(1); this.timer = setInterval(() => { this.index++; this.hasAni = true; if (this.index == this.imgs.length - 1) { setTimeout(() => { this.index = 0; this.hasAni = false; }, 750); } }, 1500); }, decativated() { clearInterval(this.timer); }, }; </script> CSS <style scoped> p { width: 30px; height: 60px; background-color: rgba(46, 139, 86, 0.356); line-height: 60px; font-size: 24px; position: absolute; top: 105px; } .tt { left: 0; } .tt1 { right: 0; } .box { width: 500px; height: 300px; margin: 100px auto; position: relative; overflow: hidden; } .box1 img { position: absolute; left: 0px; top: 0; width: 500px; height: 300px; } .animaton { transition: left 0.75s; } </style> 2. Parent component code Parent Component <keep-alive> <Lunbo :imgs="imgs" /> </keep-alive> Importing modules import Lunbo from "./components/Lunbo"; Image Data data() { return { imgs:[ require("./assets/6.jpg"), require("./assets/1.jpg"), require("./assets/2.jpg"), require("./assets/3.jpg"), require("./assets/4.jpg"), require("./assets/5.jpg"), require("./assets/6.jpg"), require("./assets/1.jpg"), ], } 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 build a standardized vmware image for kubernetes under rancher
>>: Mysql5.7.14 Linux version password forgotten perfect solution
Goal: Create a square whose side length is equal ...
This method uses the drop-shadow filter in CSS3 t...
Detailed analysis of SQL execution steps Let'...
Preface: For the implementation of digital additi...
Preface Introduction Lombok is a handy tool, just...
This article describes the Linux user and group c...
The effect achievedImplementation Code html <d...
1. Count the number of users whose default shell ...
Preface This article mainly shares with you an ex...
Preface: MySQL is a relational database managemen...
Table of contents Show Me The Code Test the effec...
After installing docker, there will usually be a ...
Table of contents 1. Get to know Teleport 2. Basi...
A colleague asked for help: the login to the back...
What Beautiful HTML Code Looks Like How to write ...