Vue项目实现vue element组件走马灯效果

我的qq 2038373094

 效果如下

(由于不支持动态图,我就截图了)

 除了实现走马灯的效果

1、自适应插入图片的高度

2、距离左侧20%;


.vue文件如下


<template> 
<el-carousel :interval="5000" arrow="always" class="d_jump" :height="imgHeight+'px'"> 
  <el-carousel-item v-for="item in imgList" :key="item.id">
     <el-row> 
       <el-col :span="24">
         <img ref="imgHeight" :src="item.idView" class="banner_img" @load="imgLoad"/>
         </el-col>
          </el-row> 
          </el-carousel-item> 
          </el-carousel> 
          </template>
<style>
  .el-carousel__item h3 {
    color: #475669;
    font-size: 14px;
    opacity: 0.75;
    line-height: 200px;
    margin: 0;
  }
  .banner_img{
    margin-left: 20%;
  }
  .el-carousel__item:nth-child(2n) {
       background-color: #d3dce6;
  }
  
  .el-carousel__item:nth-child(2n+1) {
    background-color: #d3dce6;
  }
</style>
<script>
export default {
  data() { 
    return{ 
     imgHeight:"", 
   imgList: [ {id: 0, idView: require('../../img/lb0.png')}, {id: 1, name: '详情', idView: require('../../img/lb1.png')}, {id: 2, name: '推荐', idView: require('../../img/lb2.png')},{id: 3, idView: require('../../img/lb3.png')}, ]
    }
    that.imgHeight = '620px';
     window.onresize = function temp() { // 通过点语法获取img的height属性值 
     that.imgHeight = `${that.$refs.imgHeight['0'].height}px` }

},
methods:{
  imgLoad(){
    this.$nextTick(()=>{
      this.imgHeight=this.$refs.imgHeight[0].height

    })
  }
},
mounted(){
  this.imgLoad();
  window.addEventListener('resize',()=>{
    this.imgHeight=this.$refs.imgHeight[0].height
   this.imgLoad(); 
  },false);
},

}
</script>


 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq_37591637

请给我持续更新的动力~~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值