Vue實(shí)現(xiàn)無縫輪播效果
本文實(shí)例為大家分享了Vue實(shí)現(xiàn)無縫輪播效果的具體代碼,供大家參考,具體內(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=""
: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>
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"),
],
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 使用Vue制作圖片輪播組件思路詳解
- 基于vue.js實(shí)現(xiàn)圖片輪播效果
- 基于vue.js輪播組件vue-awesome-swiper實(shí)現(xiàn)輪播圖
- Vue 過渡實(shí)現(xiàn)輪播圖效果
- vue中引用swiper輪播插件的教程詳解
- vue.js整合mint-ui里的輪播圖實(shí)例代碼
- vue.js實(shí)現(xiàn)簡單輪播圖效果
- vue輪播圖插件vue-concise-slider的使用
- 利用Vue實(shí)現(xiàn)移動(dòng)端圖片輪播組件的方法實(shí)例
- vue.js+elementUI實(shí)現(xiàn)點(diǎn)擊左右箭頭切換頭像功能(類似輪播圖效果)
相關(guān)文章
socket io與vue-cli的結(jié)合使用的示例代碼
這篇文章主要介紹了socket io與vue-cli的結(jié)合使用的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-11-11
對Vue table 動(dòng)態(tài)表格td可編輯的方法詳解
今天小編就為大家分享一篇對Vue table 動(dòng)態(tài)表格td可編輯的方法詳解,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08
vue項(xiàng)目中的遇錯(cuò):Invalid?Host?header問題
這篇文章主要介紹了vue項(xiàng)目中的遇錯(cuò):Invalid?Host?header問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-07-07
如何處理vue router 路由傳參刷新頁面參數(shù)丟失
這篇文章主要介紹了如何處理vue router 路由傳參刷新頁面參數(shù)丟失,對vue感興趣的同學(xué),可以參考下2021-05-05
Vue2?與?Vue3?的數(shù)據(jù)綁定原理及實(shí)現(xiàn)
這篇文章主要介紹了Vue2與Vue3的數(shù)據(jù)綁定原理及實(shí)現(xiàn),數(shù)據(jù)綁定是一種把用戶界面元素的屬性綁定到特定對象上面并使其同步的機(jī)制,使開發(fā)人員免于編寫同步視圖模型和視圖的邏輯2022-09-09

