国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

利用vueJs實現圖片輪播實例代碼

2019-11-19 16:25:48
字體:
來源:轉載
供稿:網友

最近新學習了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//網頁可見區域寬  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滑動效果等,純當練手。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新建县| 克拉玛依市| 离岛区| 浮山县| 苗栗市| 马关县| 彭山县| 乐清市| 郴州市| 兴仁县| 马边| 长武县| 福州市| 扶余县| 贞丰县| 桂阳县| 桃园县| 班玛县| 华宁县| 河南省| 尚义县| 荣昌县| 白山市| 古浪县| 延吉市| 嘉义县| 镶黄旗| 九台市| 桂东县| 含山县| 中山市| 那曲县| 墨脱县| 古蔺县| 灵川县| 澳门| 天峻县| 怀集县| 库伦旗| 正镶白旗| 安庆市|