利用vueJs實現(xiàn)圖片輪播實例代碼
更新時間:2017年06月03日 11:36:48 作者:南宮凌萱
本篇文章主要介紹了利用vueJs實現(xiàn)圖片輪播實例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
最近新學習了vuejs,嘗試著用vuejs寫了一個簡單的圖片輪播,便做個簡單的記錄
以下只貼出carousel.vue代碼,其他的省略
<template>
<div ref="root">
<div class="sliderPanel">
<div v-for="(item,index) in imgArray" class="verticalCenter picbox">
<transition name="slide-fade">
<img :style="{width:width,top:top}" @mouseover="clearAuto" @mouseout="slideAuto" v-show="index===selectIndex" :src="item.url" style="min-height: 100%">
</transition>
</div>
</div>
<div @click="clickLeft" @mouseover="clearAuto" @mouseout="slideAuto" class="arrowLeft verticalCenter horizaCenter">
左移
</div>
<div @click="clickRight" @mouseover="clearAuto" @mouseout="slideAuto" class="arrowRight verticalCenter horizaCenter">
右移
</div>
<div class="sliderBar horizaCenter">
<div v-for="(item,index) in imgArray" @mouseover="clearAuto" @mouseout="slideAuto" @click="setIndex(index)" class="circle" :class="{circleSelected:index===selectIndex}">
</div>
</div>
</div>
</template>
<script>
const SCREEN_WIDTH=document.body.clientWidth//網頁可見區(qū)域寬
const SCREEN_HEIGHT=document.body.scrollHeight//網頁正文全文高
var selectIndex=0
var timer=null
export default {
name: "ErCarousel",
data() {
return {
selectIndex:0,
width:'100%',
height:SCREEN_HEIGHT+'px',
top:0,
imgArray:[
{
url:'/src/components/carousel/image/1.jpg',
},
{
url:'/src/components/carousel/image/2.jpg',
},
{
url:'/src/components/carousel/image/3.jpg',
}
]
}
},
methods:{
slideAuto:function () {
var that=this;
timer=setInterval(function(){
that.clickRight();
},3000)
//clearInterval(timer);
},
clearAuto:function(){
clearInterval(timer);
},
clickLeft:function(){
if(this.selectIndex==0){
this.selectIndex=this.imgArray.length-1;
}else{
this.selectIndex--;
}
console.log(this.selectIndex);
},
clickRight:function(){
if(this.selectIndex==this.imgArray.length-1){
this.selectIndex=0;
}else{
this.selectIndex++;
}
},
setIndex:function (index) {
this.selectIndex=index;
}
},
mounted:function(){
this.slideAuto();
}
}
</script>
<style>
整個模塊也是分為了template,script,style三個部分,簡單的介紹了圖片左右切換,以及css滑動效果等,純當練手。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
vue 點擊按鈕實現(xiàn)動態(tài)掛載子組件的方法
今天小編就為大家分享一篇vue 點擊按鈕實現(xiàn)動態(tài)掛載子組件的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09
Vue+Java 通過websocket實現(xiàn)服務器與客戶端雙向通信操作
這篇文章主要介紹了Vue+Java 通過websocket實現(xiàn)服務器與客戶端雙向通信操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09
詳解在WebStorm中添加Vue.js單文件組件的高亮及語法支持
本篇文章主要介紹了詳解在WebStorm中添加Vue.js單文件組件的高亮及語法支持,非常具有實用價值,需要的朋友可以參考下2017-10-10
vue quill editor 使用富文本添加上傳音頻功能
vue-quill-editor 是vue項目中常用的富文本插件,其功能能滿足大部分的項目需求。這篇文章主要介紹了vue-quill-editor 富文本添加上傳音頻功能,需要的朋友可以參考下2020-01-01

