最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue.js輪播圖組件使用方法詳解

 更新時(shí)間:2018年07月03日 14:48:22   作者:qq_34626362  
這篇文章主要為大家詳細(xì)介紹了vue.js輪播圖組件使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

 之前用jQuery寫(xiě)過(guò)輪播組件,用的jquery動(dòng)畫(huà)實(shí)現(xiàn)的圖片滑動(dòng)效果。這個(gè)組件的滑動(dòng)特效是原生js搭配vue的數(shù)據(jù)綁定實(shí)現(xiàn)的,不依賴其他庫(kù),雖然可以再vue.js中引入swiper,但是引入類庫(kù)的最大的缺點(diǎn)就是冗余代碼太多,所以還是自己寫(xiě)一個(gè)比較好,簡(jiǎn)單扼要。(ps:組件的寬高設(shè)置還有有點(diǎn)小bug,子組件中需要改為用js動(dòng)態(tài)修改container的寬高,另外可能還有其他地方有不合理之處,歡迎各位批評(píng)指正)

github地址:git@github.com:cainiao222/vueslider-components.git

父組件代碼:

<template>
 <div>
 <slider :img="img" :width="width" :height="height"></slider>
 </div>

</template>

<script>
// import swiper from 'swiper'

 import slider from './slider1.vue'


 export default {

 data(){
 return {
 img:[{src:require('../assets/slideShow/pic1.jpg'),name:'hehe1'},
  {src:require('../assets/slideShow/pic2.jpg'),name:'hehe2'},
  {src:require('../assets/slideShow/pic3.jpg'),name:'hehe3'},
  {src:require('../assets/slideShow/pic4.jpg'),name:'hehe4'}
 ],
 width:460,
 height:250
 }
 },

 components:{
 slider:slider
 }
 }
</script>

子組件代碼:

<template>
 <div class="box">
 <div @mouseenter="endInterval" @mouseleave="startInterval" class="container">
 <div :style="{width:wrap_width+'px',height:wrap_height+'px',left:offset_left+'px'}" class="slider-wrap">
 <div class='img' v-for="item in slider_des">
  <img :src="item.src" alt="">
 </div>
 </div>
 <div class="bottom">
 <ul class="pointContainer">
  <li @click="changeIndex(index)" :class="{point:true,active:nowIndex===index}" v-for="(point,index) in length"></li>
 </ul>
 </div>
 <div @click="pre" class="click pre">&lt;</div>
 <div @click="next" class="click next">&gt;</div>
 </div>
 </div>
</template>

<script>
 export default {
 props:{
 img:{
 type:Array,
 default:[]
 },
 width:{
 type:Number,
 default:460
 },
 height:{
 type:Number,
 default:250
 }
 },

 mounted(){
 this.startInterval();
 },

 data(){
 console.log(this.width);
 return{
 length:new Array(this.img.length),
 nowIndex:0,
 wrap_width:this.width*(this.img.length+2),
 wrap_height:this.height,
 offset_left:-this.width,
 isTransition:true,
 timer:null,
 animateFlag:true,
 timerAuto:null
 }
 },
 computed:{
 slider_des:function () {
 var arr=[];
 var arr1=arr.concat(this.img);
 arr1.push(this.img[0]);
 arr1.unshift(this.img[this.img.length-1]);
 return arr1;
 }
 },
 methods:{
 pre(){
 if(this.nowIndex===0){
  if(!this.animateFlag){
  clearInterval(this.timer);
  this.animateFlag=true;
  this.offset_left=-(this.length.length)*this.width;
  }
  this.animate(-this.width,0,function (that) {
  that.offset_left=-(that.length.length)*that.width;
  });
  this.nowIndex=this.img.length-1;
  return
 }else{
  if(!this.animateFlag){
  this.animateFlag=true;
  clearInterval(this.timer);
  this.offset_left=-(this.nowIndex*this.width);
  }
  this.animate(-(this.nowIndex+1)*this.width,-(this.nowIndex*this.width));
 }
 this.nowIndex-=1;
 },
 startInterval(){
 this.timerAuto=setInterval(this.next,2000);
 },
 endInterval(){
// console.log("leave");
 clearInterval(this.timerAuto);
 },
 next(){
 if(this.nowIndex===this.length.length-1){
  if(!this.animateFlag){
  this.animateFlag=true;
  clearInterval(this.timer);
  this.offset_left=-this.width;
  }
  this.animate(-(this.length.length)*this.width,-(this.length.length+1)*this.width,function (that) {
  that.offset_left=-that.width;
  });
  this.nowIndex=0;
  return
 }else{
  if(!this.animateFlag){
  this.animateFlag=true;
  clearInterval(this.timer);
  this.offset_left=-(this.nowIndex+2)*this.width;
  }
  this.animate(-(this.nowIndex+1)*this.width,-(this.nowIndex+2)*this.width);
  this.nowIndex+=1;
 }
 },
 animate(start,end,fuc){
 var distance=end-start;
 var pre_dis=distance/50;
 var that=this;
 this.timer=setInterval(function () {
  that.animateFlag=false;
  if(Math.abs(end-that.offset_left)<=Math.abs(pre_dis)){
  that.offset_left=end;
  if(fuc){
  fuc(that);
  }
  that.animateFlag=true;
  clearInterval(that.timer);
  that.timer=null;
  return
  }
  that.offset_left+=pre_dis;
 },1);
 },
 changeIndex(index){
 clearInterval(this.timer);
 this.animate(-(this.nowIndex+1)*this.width,-(index+1)*this.width);
 this.nowIndex=index;
 }
 }
 }
</script>


<style scoped>
 *{
 margin: 0;
 list-style: none;
 /*height: 0;*/
 }
 .box{
 position: relative;
 }
 .container{
 width: 460px;
 height: 250px;
 margin: 0 auto;
 border: 1px solid #3bb4f2;
 overflow: hidden;
 left: 0;
 top: 0;
 position: absolute;
 }

 .slider-wrap{
 /*width: 2760px;*/
 /*height: 250px;*/
 position: absolute;
 /*left: -460px;*/
 /*overflow: hidden;*/
 top: 0;
 }

 .transition{
 transition: 0.5s;
 }

 .img{
 width: 460px;
 height: 250px;
 float: left;
 display: inline;
 }

 img{
 width: 460px;
 height: 250px;
 /*float: left;*/
 }

 .click{
 width: 20px;
 background-color: rgba(255,255,255,.3);
 color: aliceblue;
 font-weight: bold;
 position: absolute;
 height: 40px;
 line-height: 40px;
 margin-top: -20px;
 top: 50%;
 cursor: pointer;
 }

 .pre{
 left: 0;
 }
 .next{
 right: 0;
 }
.bottom{
 position: absolute;
 bottom: 0;
 width: 100%;
 height: 20px;
 text-align: center;
}

 .pointContainer{
 height: 20px;
 }

 .point{
 display: inline-block;
 border: 5px solid #eeeeee;
 border-radius: 5px;
 line-height: 0;
 margin-right: 3px;
 }

 .active{
 border: 5px solid #42b983;
 }

</style>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue+django實(shí)現(xiàn)下載文件的示例

    vue+django實(shí)現(xiàn)下載文件的示例

    這篇文章主要介紹了vue+django實(shí)現(xiàn)下載文件的示例,幫助大家更好的理解和學(xué)習(xí)使用vue框架,感興趣的朋友可以了解下
    2021-03-03
  • Vue中props的詳解

    Vue中props的詳解

    這篇文章主要介紹了Vue中props的詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-05-05
  • vue.js修改el-popover組件顯示位置

    vue.js修改el-popover組件顯示位置

    el-popover是一個(gè)基于element-ui框架設(shè)計(jì)的,用于浮動(dòng)展示提示或菜單的UI組件,下面這篇文章主要給大家介紹了關(guān)于vue.js修改el-popover組件顯示位置的相關(guān)資料,需要的朋友可以參考下
    2023-06-06
  • Vue監(jiān)聽(tīng)某個(gè)元素以外的區(qū)域被點(diǎn)擊問(wèn)題

    Vue監(jiān)聽(tīng)某個(gè)元素以外的區(qū)域被點(diǎn)擊問(wèn)題

    這篇文章主要介紹了Vue監(jiān)聽(tīng)某個(gè)元素以外的區(qū)域被點(diǎn)擊問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • Vue.js實(shí)現(xiàn)的表格增加刪除demo示例

    Vue.js實(shí)現(xiàn)的表格增加刪除demo示例

    這篇文章主要介紹了Vue.js實(shí)現(xiàn)的表格增加刪除demo,結(jié)合實(shí)例形式分析了vue.js數(shù)據(jù)綁定及元素增加、刪除等相關(guān)操作技巧,需要的朋友可以參考下
    2018-05-05
  • Vue項(xiàng)目History模式404問(wèn)題解決方法

    Vue項(xiàng)目History模式404問(wèn)題解決方法

    本文主要解決Vue項(xiàng)目使用History模式發(fā)布到服務(wù)器Nginx上刷新頁(yè)面404問(wèn)題。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-10-10
  • 使用vue-cli(vue腳手架)快速搭建項(xiàng)目的方法

    使用vue-cli(vue腳手架)快速搭建項(xiàng)目的方法

    本篇文章主要介紹了使用vue-cli(vue腳手架)快速搭建項(xiàng)目的方法,vue-cli 是一個(gè)官方發(fā)布 vue.js 項(xiàng)目腳手架,使用 vue-cli 可以快速創(chuàng)建 vue 項(xiàng)目,感興趣的小伙伴們可以參考一下
    2018-05-05
  • vue--vuex詳解

    vue--vuex詳解

    這篇文章主要介紹了vue--vuex的詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • vue2如何實(shí)現(xiàn)vue3的teleport

    vue2如何實(shí)現(xiàn)vue3的teleport

    這篇文章主要介紹了vue2如何實(shí)現(xiàn)vue3的teleport,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • vue獲取元素寬、高、距離左邊距離,右,上距離等還有XY坐標(biāo)軸的方法

    vue獲取元素寬、高、距離左邊距離,右,上距離等還有XY坐標(biāo)軸的方法

    今天小編就為大家分享一篇vue獲取元素寬、高、距離左邊距離,右,上距離等還有XY坐標(biāo)軸的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-09-09

最新評(píng)論

德钦县| 鄂温| 高台县| 阿拉善左旗| 定日县| 浪卡子县| 杭锦后旗| 宁阳县| 六枝特区| 滦南县| 龙岩市| 米林县| 郓城县| 武穴市| 棋牌| 永德县| 奈曼旗| 盘锦市| 西乌| 湘西| 织金县| 通城县| 福清市| 蒙自县| 容城县| 瓦房店市| 富平县| 酒泉市| 西乌| 建瓯市| 应用必备| 武夷山市| 开封县| 于田县| 安宁市| 伊宁市| 马龙县| 军事| 乡宁县| 大渡口区| 本溪|