vue实现幻灯片切换效果

本文介绍如何利用Vue.js结合HTML和CSS3来实现动态幻灯片切换效果。首先,设置HTML结构,然后通过Vue.js进行数据绑定和事件监听以控制幻灯片的显示和切换,最后应用CSS样式完成动画效果。

1、html

<div class="forestScene">
    <div class="forestScenePic">
        <div class="activePhoto">
            <img :src="indexData.photos[indexData.activePhoto]">
        </div>
        <div class="smallPicture">
            <div class="thumbnail" v-for="(item, index) in indexData.photos" :key="index"
                 @click="changePhoto(index)" :class="{'active': indexData.activePhoto == index}">
                <img :src="item">
            </div>
        </div>
    </div>
</div>

2、Vue.js

data () {
    rerurn {
        activePhoto: '',
        photos: [
          require('@/assets/img/dataCenter/forest.jpg'),
          require('@/assets/img/dataCenter/forest.jpg'),
          require('@/assets/img/dataCenter/forest.jpg'),
          require('@/assets/img/dataCenter/forest.jpg'),
          require('@/assets/img/dataCenter/forest.jpg'),
          require('@/assets/img/dataCenter/forest.jpg'),
          require('@/assets/img/dataCenter/forest.jpg'),
          require('@/assets/img/dataCenter/forest.jpg')
        ]
    }
},
mounted () {
    this.changePhoto(0)
}
methods: {
    changePhoto (index) {
      this.indexData.activePhoto = index
    },
    nextPhoto () {
      this.changePhoto(this.indexData.activePhoto + 1 < this.indexData.photos.length ? this.indexData.activePhoto + 1 : 0)
    },
    previousPhoto () {
      this.changePhoto(this.indexData.activePhoto - 1 >= 0 ? this.indexData.activePhoto - 1 : this.indexData.photos.length - 1)
    }
}

3、CSS

.forestScene{
  display: block;
  height: 780px;
  overflow: hidden;
  margin: 0 auto;
}
.forestScenePic{
  .activePhoto{
    margin: 0 auto 10px auto;
    width: 99%;
    height: 545px;
    overflow: hidden;
  }
  .activePhoto img{
    width: 100%;
    height: 545px;
    border: 3px solid #006cbf;
    position: relative;
    border-radius: 10px;
  }
  .smallPicture .thumbnail{
    width: 19%;
    height: 100px;
    margin: 5px 0.5% 0 0.5%;
    display: inline-block;
    overflow: hidden;
  }
  .smallPicture .thumbnail img{
    width: 100%;
    height: 100px;
    border: 1px solid #fff;
    cursor: pointer;
    opacity: 1;
  }
  .smallPicture .thumbnail:hover img{
    opacity: 0.6;
  }
  .smallPicture .thumbnail.active img{
    border-color: #05FFF9;
    opacity: 1;
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值