您好,登錄后才能下訂單哦!
這篇文章主要介紹Vue如何實(shí)現(xiàn)無縫輪播效果,文中介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們一定要看完!
具體內(nèi)容如下
1.子組件代碼
代碼如下(示例):
<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="" : :class="hasAni ? 'animaton' : ''" /> </li> </ul> <p class="tt" @click="left"><</p> <p class="tt1" @click="right">></p> </div> </div> </template>
script代碼如下(示例):
<script> export default { name: "Lunbo", props: ["imgs"], data() { return { // js中使用圖片,需要采用require導(dǎo)入 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.父組件代碼
父組件
<keep-alive> <Lunbo :imgs="imgs" /> </keep-alive>
導(dǎo)入模塊
import Lunbo from "./components/Lunbo";
圖片數(shù)據(jù)
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"), ], }
以上是“Vue如何實(shí)現(xiàn)無縫輪播效果”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。