vueJs が画像カルーセルを実装する方法のサンプルコード共有

黄舟
リリース: 2017-06-04 10:47:27
オリジナル
1423 人が閲覧しました

この記事では主にvueJsを使ってpicturecarouselを実装するサンプルコードを紹介していますが、編集者がとても良いと思ったので、参考として共有します。エディターをフォローして見てみましょう

最近vuejsを勉強して、vuejsを使って簡単な画像カルーセルを書いてみたので簡単に記録してみました

以下にcarousel.vueのコードのみ載せ、他は割愛します

<template> 
 <p ref="root">   
  <p class="sliderPanel"> 
   <p 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> 
   </p> 
  </p> 
  <p @click="clickLeft" @mouseover="clearAuto" @mouseout="slideAuto" class="arrowLeft verticalCenter horizaCenter"> 
     左移 
  </p> 
  <p @click="clickRight" @mouseover="clearAuto" @mouseout="slideAuto" class="arrowRight verticalCenter horizaCenter"> 
    右移 
  </p> 
  <p class="sliderBar horizaCenter"> 
   <p v-for="(item,index) in imgArray" @mouseover="clearAuto" @mouseout="slideAuto" @click="setIndex(index)" class="circle" :class="{circleSelected:index===selectIndex}"> 
   </p> 
  </p> 
 </p> 
</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:&#39;100%&#39;, 
      height:SCREEN_HEIGHT+&#39;px&#39;, 
      top:0, 
      imgArray:[ 
       { 
        url:&#39;/src/components/carousel/image/1.jpg&#39;, 
       }, 
       { 
        url:&#39;/src/components/carousel/image/2.jpg&#39;, 
       }, 
       { 
        url:&#39;/src/components/carousel/image/3.jpg&#39;, 
       } 
      ] 
    } 
  }, 
  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>
ログイン後にコピー

モジュール全体も、テンプレート、スクリプト、スタイルの 3 つの部分に分かれており、画像の左右の切り替えや CSS のスライド効果などが簡単に紹介されています。これは純粋に練習用です。

以上がvueJs が画像カルーセルを実装する方法のサンプルコード共有の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!