实现一个旋转木马样式的轮播

本文介绍了如何在Vue项目中使用vue-carousel-3d插件创建一个具有3D效果的图片轮播组件,展示了HTML模板、JavaScript代码和CSS样式,以及如何通过点击事件跳转到详细页面。
摘要由CSDN通过智能技术生成

最终实现成果

代码

使用了vue-carousel-3d插件

npm install -S vue-carousel-3d

<template>
  <div class='cultureCarousel'>
    <img src="../../img/culture/fazhan.png" alt="" style="width: 100%; height: 200px;margin-bottom: 20px;" />
    <div class="box" v-if="list?.length>0">
      <carousel-3d :perspective="35" :display="5" :width="250" :height="400" :space="50">
        <slide v-for="(item, i) in list" :index="i" :key="i" >
          <template slot-scope="obj">
            <div class="con" @click="imgClick(item,obj)">
              <img :src="item.img_path" />
              <div class="title">{{ item.title }}</div>
              <div class="text">{{ item.abstract }}</div>
            </div>
            
          </template>
        </slide>
      </carousel-3d>
    </div>
  </div>
</template>
//js部分
<script>
  import { Carousel3d, Slide } from 'vue-carousel-3d'
  /* eslint-disable */
  export default {
    components: { Carousel3d, Slide },
    props: {
      info: {
        type: Object,
        default: () => {},
      },
    },
    computed:{
      list(){
        return this.info.child
      },
    },
    data() {
      return {
      }
    },

    methods: {
      imgClick(item,obj) {
        if(obj.isCurrent){
          const { href } = this.$router.resolve({
            name: 'NewsDetails', 
            query:{main_uuid:item.main_uuid}
          })
          window.open(href, '_blank')
        }
        
      },
    },
  }
</script>
//css部分
<style lang="less" scoped>
  .left-1 {
    transform: translateX(-400px) translateZ(-400px) rotateY(-35deg) !important;
  }
  .right-1 {
    transform: translateX(400px) translateZ(-400px) rotateY(35deg) !important;
  }
.cultureCarousel{
  height: 100%;
  .box{
    height: calc(100% - 240px);
  }
  .con{
    padding: 25px;
    img{
      height: 140px;
    }
  }
  .text{
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-line-clamp: 4;

    line-height: 1.5;
    color: black;
    font-size: 16px;
  }
  .title{
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 18px;
    height: 80px;
    color: #F19855;
  }

  .carousel-3d-slide{
    background-color: #F3F3F3 !important;
  }
  .current{
    background-color: #F8E8DB !important;
    border:1.5px solid #F19855 !important;
  }
}
  
</style>

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值