(Carousel)解决:Element-ui 中 Carousel 走马灯的样式的修改问题

这篇具有很好参考价值的文章主要介绍了(Carousel)解决:Element-ui 中 Carousel 走马灯的样式的修改问题。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

Ⅰ、Element-ui 提供的组件与想要目标情况的对比:

1、Element-ui 提供组件情况:

其一、Element-ui 自提供的代码情况为(示例的代码,例子如下):
el-carousel,# Element-ui 专栏,vue.js,element-ui,经验分享,carousel,样式修改

// Element-ui 自提供的代码:
<template>
  <el-carousel :interval="5000" arrow="always">
    <el-carousel-item v-for="item in 4" :key="item">
      <h3>{{ item }}</h3>
    </el-carousel-item>
  </el-carousel>
</template>

<style>
  .el-carousel__item h3 {
    color: #475669;
    font-size: 18px;
    opacity: 0.75;
    line-height: 300px;
    margin: 0;
  }
  
  .el-carousel__item:nth-child(2n) {
    background-color: #99a9bf;
  }
  
  .el-carousel__item:nth-child(2n+1) {
    background-color: #d3dce6;
  }
</style>

代码地址:https://element.eleme.cn/#/zh-CN/component/carousel

其二、页面的显示情况为:

el-carousel,# Element-ui 专栏,vue.js,element-ui,经验分享,carousel,样式修改

Ⅱ、实现 Carousel 走马灯样式变化的过程:

1、 Carousel 自提供的代码的实践:

其一、代码为:

<template>
    <div>
        <div style="font-weight:bolder; font-size:20px">走马灯的使用:</div>
        <div>
            <div style="margin:20px 0;">方法一:原本样式</div>
            <div class="block" style="width:50%;">
                <el-carousel :interval="5000" arrow="always">
                    <el-carousel-item v-for="item in arrayList" :key="item">
                    <h3>{{ item }}</h3>
                    </el-carousel-item>
                </el-carousel>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            arrayList:['王二','张三','李四','麻五']
        }
    }
}
</script>

<style lang="scss" scoped>
.block {
  .el-carousel__item h3 {
    color: #475669;
    font-size: 18px;
    opacity: 0.75;
    line-height: 100px;
    margin: 0;
  }
  .el-carousel__item:nth-child(2n) {
    background-color: #99a9bf;
  }
  .el-carousel__item:nth-child(2n+1) {
    background-color: #d3dce6;
  }
  // 此时是:设置 carousel 走马灯的高度为:100px;
  /deep/.el-carousel__container {  
    height: 100px;
  }
}
</style>

其二、页面展示为:

el-carousel,# Element-ui 专栏,vue.js,element-ui,经验分享,carousel,样式修改

2、 Carousel 代码相关属性的使用:

其一、indicator-position(指示器) 属性的使用:

A、代码:

indicator-position="none"     //此时的指示器就不显示了;

indicator-position="outside"  //表示指示器在外面显示;
// 而默认不设置的指示器是在里面的;

B、状态显示:

//显示器不显示的情况:
el-carousel,# Element-ui 专栏,vue.js,element-ui,经验分享,carousel,样式修改

//显示器在内部的情况:
el-carousel,# Element-ui 专栏,vue.js,element-ui,经验分享,carousel,样式修改

//显示器在外部的情况:
el-carousel,# Element-ui 专栏,vue.js,element-ui,经验分享,carousel,样式修改

其二、arrow(箭头) 属性的使用:

A、代码:

arrow="always"     //此时是:箭头一直显示;

arrow="never"     //此时是:箭头不再显示;

// 默认是 hover 时箭头才显示(即:不设置 arrow 属性时)

B、状态显示:

//箭头一直显示的情况:

el-carousel,# Element-ui 专栏,vue.js,element-ui,经验分享,carousel,样式修改

//箭头不显示的情况:
el-carousel,# Element-ui 专栏,vue.js,element-ui,经验分享,carousel,样式修改

//箭头 hover 时显示的情况(即:此时仅 hover 时才显示箭头):

el-carousel,# Element-ui 专栏,vue.js,element-ui,经验分享,carousel,样式修改

其三、direction(方向) 属性的使用:

A、代码:

direction="vertical"  //此时表示:让走马灯在垂直方向上显示;

 //而默认是:走马灯在水平方向上显示;

B、状态显示:

// 走马灯在水平方向上显示为:

el-carousel,# Element-ui 专栏,vue.js,element-ui,经验分享,carousel,样式修改

// 走马灯在垂直方向上显示为:

el-carousel,# Element-ui 专栏,vue.js,element-ui,经验分享,carousel,样式修改

其四、autoplay(是否自动播放) 属性的使用:

:autoplay="false"   //此时表示是:非自动播放;

//而默认是:自动播放;

3、 Carousel 代码相关样式修改的过程:

其一、走马灯高度设置:

  /deep/.el-carousel__container {
      height: 60px;  
    }

其二、设置 item 背景色:

/deep/.el-carousel {
    .el-carousel__item {
      background-color: #ccc;  //设置每一个 item 待切换页面的背景色;
      margin-top: 0px;
    }
  }

其三、调整箭头大小:

 /deep/.el-carousel__arrow{
    font-size: 20px;
  }

其四、调整箭头的位置:

/deep/.el-carousel__arrow--left,
  /deep/.el-carousel__arrow--right{
    background-color: transparent !important; // 此时是将其外面的圆框变成透明(即:彻底消失);
    position: relative;
    top: 7px;
  }
  /deep/.el-carousel__arrow--left {
      left: 20px;
  }
  /deep/.el-carousel__arrow--right {
      left: 80px;
  }

3、 Carousel 代码相关样式修改的整体代码为:

其一、代码为:

<template>
    <div>
        <div>
            <div style="margin:20px 0;">方式二:修改后的样式</div><!-- 可以通过该 div 调整走马灯的位置; -->
            <div class="project" style="width:80%;margin-top:20px;"><!-- 通过外层的 project 类来调整走马灯的位置; -->
                <el-carousel :interval="5000" arrow="none" indicator-position="none" style="margin-top:20px;">
                  <!-- 也可以通过 el-carousel 的设置 style 属性来调整走马灯的位置; -->
                    <el-carousel-item v-for="item in arrayList" :key="item">
                    <h3>{{ item }}</h3>
                    </el-carousel-item>
                </el-carousel>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            arrayList:['王二','张三','李四','麻五']
        }
    }
}
</script>

<style lang="scss" scoped>
.project {
  //下面代码:此时是调整 arrayList 值的大小和位置;
  .el-carousel__item h3 {
    line-height: 60px;   //此时是调整 arrayList 的值上下位置;
    text-align: center;  //此时是使 arrayList 的值居中;
    font-size: 18px;
    opacity: 0.75;
  }

  //下面代码:此时是调整走马灯的高度,但设置不了盒子上面的距离(暂时没找到合适的 css 位置);
  /deep/.el-carousel__container {
      height: 60px;  
    }

  /deep/.el-carousel {
    .el-carousel__item {
      background-color: #ccc;  //设置每一个 item 待切换页面的背景色;
      margin-top: 0px;
    }
  }

  //下面代码:此时是调整箭头的大小;
  /deep/.el-carousel__arrow{
    font-size: 20px;
  }

  //下面代码:此时是调整箭头的位置; 
  /deep/.el-carousel__arrow--left,
  /deep/.el-carousel__arrow--right{
    background-color: transparent !important; // 此时是将其外面的圆框变成透明(即:彻底消失);
    position: relative;
    top: 7px;
  }
  /deep/.el-carousel__arrow--left {
    left: 20px;
  }
  /deep/.el-carousel__arrow--right {
    left: 80px;
  }
}
</style>

其二、页面显示为:

el-carousel,# Element-ui 专栏,vue.js,element-ui,经验分享,carousel,样式修改

Ⅲ、实现 Carousel 走马灯样式的整体代码与显示结果:

1、整体代码为:

<template>
    <div>
        <div style="font-weight:bolder; font-size:20px">走马灯的使用:</div>
        <div>
            <div style="margin:20px 0;">方法一:原本样式</div>
            <div class="block" style="width:50%;">
                <el-carousel :interval="5000" arrow="always">
                    <el-carousel-item v-for="item in arrayList" :key="item">
                    <h3>{{ item }}</h3>
                    </el-carousel-item>
                </el-carousel>
            </div>
        </div>
        <div>
            <div style="margin:20px 0;">方式二:修改后的样式</div><!-- 可以通过该 div 调整走马灯的位置; -->
            <div class="project" style="width:80%;margin-top:20px;"><!-- 通过外层的 project 类来调整走马灯的位置; -->
                <el-carousel :interval="5000" arrow="none" indicator-position="none" style="margin-top:20px;">
                  <!-- 也可以通过 el-carousel 的设置 style 属性来调整走马灯的位置; -->
                    <el-carousel-item v-for="item in arrayList" :key="item">
                    <h3>{{ item }}</h3>
                    </el-carousel-item>
                </el-carousel>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            arrayList:['王二','张三','李四','麻五']
        }
    }
}
</script>

<style lang="scss" scoped>
.block {
  .el-carousel__item h3 {
    color: #475669;
    font-size: 18px;
    opacity: 0.75;
    line-height: 100px;
    margin: 0;
  }
  .el-carousel__item:nth-child(2n) {
    background-color: #99a9bf;
  }
  .el-carousel__item:nth-child(2n+1) {
    background-color: #d3dce6;
  }
  /deep/.el-carousel__container {
    height: 100px;
  }
}
.project {
  //备用代码: 可能需要的 hover 状态;
  // &:hover {
    // /deep/.el-carousel__arrow--left,
    // /deep/.el-carousel__arrow--right{
    //     background-color: transparent !important;
    //     position: relative;
    //     top: 7px;
    // }
    // /deep/.el-carousel__arrow--left {
    //   left: -67px;
    // }
    // /deep/.el-carousel__arrow--right {
    //   right: -67px;
    // }
  // }

  //下面代码:此时是调整 arrayList 值的大小和位置;
  .el-carousel__item h3 {
    line-height: 60px;   //此时是调整 arrayList 的值上下位置;
    text-align: center;  //此时是使 arrayList 的值居中;
    font-size: 18px;
    opacity: 0.75;
  }

  //下面代码:此时是调整走马灯的高度,但设置不了盒子上面的距离(暂时没找到合适的 css 位置);
  /deep/.el-carousel__container {
      height: 60px;  
    }

  /deep/.el-carousel {
    .el-carousel__item {
      background-color: #ccc;  //设置每一个 item 待切换页面的背景色;
      margin-top: 0px;
    }
  }

  //下面代码:此时是调整箭头的大小;
  /deep/.el-carousel__arrow{
    font-size: 20px;
  }

  //下面代码:此时是调整箭头的位置; 
  /deep/.el-carousel__arrow--left,
  /deep/.el-carousel__arrow--right{
    background-color: transparent !important; // 此时是将其外面的圆框变成透明(即:彻底消失);
    position: relative;
    top: 7px;
  }
  /deep/.el-carousel__arrow--left {
    left: 20px;
  }
  /deep/.el-carousel__arrow--right {
    left: 80px;
  }
}

</style>

2、显示结果为:

el-carousel,# Element-ui 专栏,vue.js,element-ui,经验分享,carousel,样式修改

Ⅳ、小结:

其一、哪里有不对或不合适的地方,还请大佬们多多指点和交流!
其二、有兴趣的话,可以多多关注这个专栏(Vue(Vue2+Vue3)面试必备专栏):https://blog.csdn.net/weixin_43405300/category_11525646.html?spm=1001.2014.3001.5482文章来源地址https://www.toymoban.com/news/detail-822374.html

到了这里,关于(Carousel)解决:Element-ui 中 Carousel 走马灯的样式的修改问题的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 自定义element-ui走马灯(轮播)样式

    自定义el-carousel-item指示器样式 把指示器变成圆点 效果图:  

    2024年02月13日
    浏览(32)
  • Element UI 走马灯的使用

    目录 走马灯是什么 原生js实现 Element UI的走马灯使用 el-carousel Carousel Events el-carousel-item 在有限空间内,循环播放同一类型的图片、文字等内容,走马灯也叫轮播图。 比如   JS实现轮播图效果(同时播放音频)_trigger333的博客-CSDN博客 Element - The world\\\'s most popular Vue UI framework 代

    2024年02月02日
    浏览(41)
  • elementUI 轮播图 ----Carousel 走马灯笔记

    2024年02月05日
    浏览(117)
  • ElementUI浅尝辄止14:Carousel 走马灯

    在有限空间内,循环播放同一类型的图片、文字等内容 结合使用 el-carousel 和 el-carousel-item 标签就得到了一个走马灯。幻灯片的内容是任意的,需要放在 el-carousel-item 标签中。默认情况下,在鼠标 hover 时底部的指示器时就会触发切换。通过设置 trigger 属性为 click ,可以达到点

    2024年02月10日
    浏览(35)
  • 制作轮播图经验分享——element ui走马灯的使用(附源码,效果截图)

    先附上效果图:   element ui链接地址:Carousel 走马灯 | Element Plus (gitee.io) 源码: 这里我使用的是静态图片(本地) 经验分享: 在制作轮播图的时候经常会发现图片大小不一,这时候可以在img标签里加上width:100%;height:100%即可实现图片铺满。 当然,这只是轮播图的一种,还

    2024年02月11日
    浏览(32)
  • element-plus走马灯不显示

    依赖正确,代码用法正确,但是element-plu走马灯就是不显示!! 并且盒子的宽度总是0 在现有的布局中插入官方的案例,也不能显示 但是把整个页面都使用官方案例就可以正常显示 所以,怀疑时自己的样式冲突了 就content一个盒子,看到 display: flex; 就知道不对劲,去掉flex布

    2024年02月07日
    浏览(27)
  • 用 React+ts 实现无缝滚动的走马灯

    走马灯是一种常见的网页交互组件,可以展示多张图片或者内容,通过自动播放或者手动切换的方式,让用户能够方便地浏览多张图片或者内容。 本次实现的不是轮播图而是像传送带一样的无限滚动的形式。 走马灯可设置一下属性: 滚动速度 滚动方向 一屏要显示项的个数

    2024年02月13日
    浏览(28)
  • 实现NoticeBar 通知栏。走马灯公告栏

    微信小程序封装公共组件——实现NoticeBar 通知栏。走马灯公告栏 代码如下(示例): index.wxml代码如下(示例): index.ts 公告通知栏父组件传notice数组,组件设置了timer可以多条进行轮播

    2024年02月10日
    浏览(40)
  • Proteus仿真--基于51单片机的走马灯实现(仿真文件+程序)

    本文主要介绍基于51单片机的走马灯仿真(完整仿真源文件及代码见文末链接) 本设计中有16个LED灯用于流水走马演示,一位数码管用于显示当前模式状态,3个按键分别用于选择模式及加减速度控制 仿真图如下 其中 K1:用于模式切换选择,有多种模式可切换 K2:加速流水/走

    2024年02月06日
    浏览(39)
  • transition 实现div伸缩动画、3D翻转动画(vue版)、elementui走马灯

    代码   template     div         div               el-carousel :interval=\\\"4000\\\" type=\\\"card\\\" height=\\\"500px\\\"                   el-carousel-item v-for=\\\"(i,index) in imageData\\\" :key=\\\"index\\\"                     img :src=\\\"i.src\\\" style=\\\"width: 100%;height: 100%;\\\"                   /el-carousel-item       

    2024年02月02日
    浏览(26)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包