首頁 > web前端 > js教程 > 基於vue.js實作圖片輪播效果

基於vue.js實作圖片輪播效果

高洛峰
發布: 2016-12-03 09:43:05
原創
2440 人瀏覽過

輪播圖效果:

基於vue.js實作圖片輪播效果

基於vue.js實作圖片輪播效果

html

<template>
 <div class="shuffling">
 <div class="fouce fl">
 <div class="focus">
 <ul class="showimg">
 <template v-for=&#39;sd in shufflingData&#39;>
  <li v-if=&#39;shufflingId==$index&#39; v-on:mouseover=&#39;showPreNext&#39; v-on:mouseout=&#39;hiddenPreNext&#39;>
  <a target="_blank" title="{{sd.title}}" class="img" href="{{sd.href}}"><img alt="{{sd.title}}" v-bind:src="sd.url"/></a>
  <h3><a target="_blank" title="{{sd.title}}" href="{{sd.href}}">{{sd.title}}</a></h3>
  </li>
  </template>
 </ul>
 <div class=&#39;bullet-pagination&#39;>
  <a class="bullet" v-bind:class="{&#39;active&#39;: shufflingId==0}" v-on:click=&#39;bulletFunOne&#39;></a>
  <a class="bullet" v-bind:class="{&#39;active&#39;: shufflingId==1}" v-on:click=&#39;bulletFunTwo&#39;></a>
  <a class="bullet" v-bind:class="{&#39;active&#39;: shufflingId==2}" v-on:click=&#39;bulletFunThree&#39;></a>
 </div>
 <div v-show=&#39;PreNext&#39; class="preNext pre" v-on:mouseover=&#39;showPreNext&#39; v-on:mouseout=&#39;hiddenPreNext&#39; v-on:click=&#39;preFun&#39;></div>
 <div v-show=&#39;PreNext&#39; class="preNext next" v-on:mouseover=&#39;showPreNext&#39; v-on:mouseout=&#39;hiddenPreNext&#39; v-on:click=&#39;nextFun&#39;></div>
 </div>
 </div>
 </div>
</template>
登入後複製

js

<script>
export default {
 components: {
 },
 ready: function() {
 var _this=this;
 var timer = setInterval(function() {
 if(_this.shufflingId>=0&&_this.shufflingId<_this.shufflingData.length-1){
 _this.shufflingId=parseInt(_this.shufflingId)+1;
 }
 else if (_this.shufflingId==_this.shufflingData.length-1) {
 _this.shufflingId=0;
 }
 }, 5000)
 },
 methods: {
 bulletFunOne:function(){
 this.shufflingId=0;
 },
 bulletFunTwo:function(){
 this.shufflingId=1;
 },
 bulletFunThree:function(){
 this.shufflingId=2;
 },
 showPreNext:function(){
 this.PreNext=true;
 },
 hiddenPreNext:function(){
 this.PreNext=false;
 },
 preFun:function(){
 var _this=this;
 if(_this.shufflingId>0&&_this.shufflingId<_this.shufflingData.length){
 _this.shufflingId=parseInt(_this.shufflingId)-1;
 }
 },
 nextFun:function(){
 var _this=this;
 if(_this.shufflingId>=0&&_this.shufflingId<_this.shufflingData.length-1){
 _this.shufflingId=parseInt(_this.shufflingId)+1;
 }
 }
 },
 data() {
 return {
 shufflingData:[{
 title:&#39;喵来个米&#39;,
 href:&#39;1&#39;,
 url:&#39;/xxx/xx/src/img/1.png&#39;
 },
 {
 title:&#39;豆豆&#39;,
 href:&#39;2&#39;,
 url:&#39;/xxx/xx/src/img/2.png&#39;
 },{
 title:&#39;猫咪咪&#39;,
 href:&#39;3&#39;,
 url:&#39;/xxx/xx/src/img/3.jpg&#39;
 }],
 shufflingId:0,
 PreNext:false,
 }
 }
}
</script>
登入後複製

css

.fouce {
 position: relative;
 left:380px;
 overflow: hidden;
 height: 570px;
 width: 1100px;
}
.fl {
 float: left;
}
.focus{
 overflow: hidden;
}
.fouce ul {
 position: absolute;
}
.fouce ul li {
 float: left;
}
.fouce ul li a.img {
 display: block;
 height: 520px;
}
.showimg{
 width:1440px;
 left:-0px;
}
.showimg img {
 display: block;
 width:1100px;
 height:520px;
}
.fouce .bullet-pagination {
 position: absolute;
 bottom: 50px;
}
.fouce ul li h3 {
 height: 40px;
 line-height: 40px;
 background-color: #ededed;
 text-align: center;
 font-size: 25px;
 width: 1100px;
}
.bullet-pagination {
 width: 100%;
 text-align: center;
 padding-top: 16px;
 clear: both;
 overflow: hidden;
}
.bullet {
 display: inline-block;
 background: #fff;
 width: 12px;
 height: 12px;
 border-radius: 6px;
 -webkit-border-radius: 6px;
 margin-right: 5px;
 opacity: 0.8;
 -webkit-transition: opacity 0.8s linear;
 -moz-transition: opacity 0.8s linear;
 -ms-transition: opacity 0.8s linear;
 -o-transition: opacity 0.8s linear;
 transition: opacity 0.8s linear;
}
.bullet.active {
 background: #007cdb;
 opacity: 1;
 cursor: pointer;
}
.preNext {
 display: block;
 width: 31px;
 height: 41px;
 position: absolute;
 top: 200px;
 cursor: pointer;
}
.pre {
 background: url(&#39;/xxx/xx/src/img/news_arr_r.png&#39;) no-repeat right center;
}
.next {
 background: url(&#39;/xxx/xx/src/img/news_arr_r.png&#39;) no-repeat left center;
 right: 0px;
}
* {
 padding: 0;
 margin: 0;
 list-style: none;
}
a{
 text-decoration: none;
}
登入後複製

js
rrreee

css🎜rrreee🎜🎜🎜
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板