使用el-carousel默认高度300px问题

1、使用走马灯进行轮播

<el-row>
  <el-col :span="24">
    <el-carousel style="padding: 0;" id="el-carousel">
      <el-carousel-item v-for="(item, index) in shouyelist" :key="index">
        <el-image :src="item" style="width: 100%;transform: scaleY(1)">
          <div slot="placeholder" class="image-slot">
            加载中<span class="dot">...</span>
          </div>
        </el-image>
      </el-carousel-item>
    </el-carousel>
  </el-col>
</el-row>

2、在el-carousel里面,会有一个样式el-carousel__container,默认高度300px;,因此在浏览器大小有变动的时候,导致图变形等情况出现。需要修改一下

.el-carousel__container{
  /*height: 456px;*/
  height: 100% !important;
}

3、增加变形的JS控制

// 在methods里面
setSize1: function() {
  var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  this.screenWidth = width;
  //图片                高 / 宽  700 / 1920
  this.bannerHeight = 456 / 1920 * this.screenWidth - 50
  document.getElementById('el-carousel').style.height = this.bannerHeight + 'px';

},
setSize: function() {
  this.bannerHeight = 456 / 1920 * this.screenWidth - 50
  document.getElementById('el-carousel').style.height = this.bannerHeight + 'px';
}

mounted() {
  this.setSize1();
  const that = this;
  //监听浏览器窗口大小改变
  window.addEventListener('resize', function() {
    var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
    that.screenWidth = width;
    that.setSize();
  }, false);

}

4、搞掂,收工!!

欢迎大家关注我,it4eye!!!!

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

psyuhen

你的鼓励是我最大的动力谢谢支持

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

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

打赏作者

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

抵扣说明:

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

余额充值