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
Table partitioning is different from database par...
This article mainly introduces the effect of div ...
This article shares the data display code for Jav...
A simple record of the database startup problems ...
Table of contents Add traffic function to github+...
Record the installation and use of openssh-server...
Table of contents Preface 1. EndPoint 2. Connecti...
To use Nginx under Windows, we need to master som...
When I first started designing web pages using XH...
This article describes the example of MySQL sched...
Install TomCat on Windows This article will intro...
After the server where Docker is located has been...
Table of contents 1. Live broadcast effect 2. Ste...
Install related dependencies npm i lib-flexible -...
Scenario Requirements 1. We can use the script fu...