zoukankan      html  css  js  c++  java
  • Carousel 走马灯

    在有限空间内,循环播放同一类型的图片、文字等内容

     

    基础用法

     

    适用广泛的基础用法

    结合使用el-carouselel-carousel-item标签就得到了一个走马灯。幻灯片的内容是任意的,需要放在el-carousel-item标签中。默认情况下,在鼠标 hover 底部的指示器时就会触发切换。通过设置trigger属性为click,可以达到点击触发的效果。

     1 <template>
     2   <div class="block">
     3     <span class="demonstration">默认 Hover 指示器触发</span>
     4     <el-carousel height="150px">
     5       <el-carousel-item v-for="item in 4" :key="item">
     6         <h3>{{ item }}</h3>
     7       </el-carousel-item>
     8     </el-carousel>
     9   </div>
    10   <div class="block">
    11     <span class="demonstration">Click 指示器触发</span>
    12     <el-carousel trigger="click" height="150px">
    13       <el-carousel-item v-for="item in 4" :key="item">
    14         <h3>{{ item }}</h3>
    15       </el-carousel-item>
    16     </el-carousel>
    17   </div>
    18 </template>
    19 
    20 <style>
    21   .el-carousel__item h3 {
    22     color: #475669;
    23     font-size: 14px;
    24     opacity: 0.75;
    25     line-height: 150px;
    26     margin: 0;
    27   }
    28 
    29   .el-carousel__item:nth-child(2n) {
    30      background-color: #99a9bf;
    31   }
    32   
    33   .el-carousel__item:nth-child(2n+1) {
    34      background-color: #d3dce6;
    35   }
    36 </style>
    View Code

     

    指示器

     

    可以将指示器的显示位置设置在容器外部

    indicator-position属性定义了指示器的位置。默认情况下,它会显示在走马灯内部,设置为outside则会显示在外部;设置为none则不会显示指示器。

     1 <template>
     2   <el-carousel indicator-position="outside">
     3     <el-carousel-item v-for="item in 4" :key="item">
     4       <h3>{{ item }}</h3>
     5     </el-carousel-item>
     6   </el-carousel>
     7 </template>
     8 
     9 <style>
    10   .el-carousel__item h3 {
    11     color: #475669;
    12     font-size: 18px;
    13     opacity: 0.75;
    14     line-height: 300px;
    15     margin: 0;
    16   }
    17   
    18   .el-carousel__item:nth-child(2n) {
    19     background-color: #99a9bf;
    20   }
    21   
    22   .el-carousel__item:nth-child(2n+1) {
    23     background-color: #d3dce6;
    24   }
    25 </style>
    View Code

    切换箭头

    可以设置切换箭头的显示时机

    arrow属性定义了切换箭头的显示时机。默认情况下,切换箭头只有在鼠标 hover 到走马灯上时才会显示;若将arrow设置为always,则会一直显示;设置为never,则会一直隐藏。

     1 <template>
     2   <el-carousel :interval="5000" arrow="always">
     3     <el-carousel-item v-for="item in 4" :key="item">
     4       <h3>{{ item }}</h3>
     5     </el-carousel-item>
     6   </el-carousel>
     7 </template>
     8 
     9 <style>
    10   .el-carousel__item h3 {
    11     color: #475669;
    12     font-size: 18px;
    13     opacity: 0.75;
    14     line-height: 300px;
    15     margin: 0;
    16   }
    17   
    18   .el-carousel__item:nth-child(2n) {
    19     background-color: #99a9bf;
    20   }
    21   
    22   .el-carousel__item:nth-child(2n+1) {
    23     background-color: #d3dce6;
    24   }
    25 </style>
    View Code

    卡片化

    当页面宽度方向空间空余,但高度方向空间匮乏时,可使用卡片风格

    type属性设置为card即可启用卡片模式。从交互上来说,卡片模式和一般模式的最大区别在于,可以通过直接点击两侧的幻灯片进行切换。

     1 <template>
     2   <el-carousel :interval="4000" type="card" height="200px">
     3     <el-carousel-item v-for="item in 6" :key="item">
     4       <h3>{{ item }}</h3>
     5     </el-carousel-item>
     6   </el-carousel>
     7 </template>
     8 
     9 <style>
    10   .el-carousel__item h3 {
    11     color: #475669;
    12     font-size: 14px;
    13     opacity: 0.75;
    14     line-height: 200px;
    15     margin: 0;
    16   }
    17   
    18   .el-carousel__item:nth-child(2n) {
    19     background-color: #99a9bf;
    20   }
    21   
    22   .el-carousel__item:nth-child(2n+1) {
    23     background-color: #d3dce6;
    24   }
    25 </style>
    View Code
    参数说明类型可选值默认值
    height 走马灯的高度 string
    initial-index 初始状态激活的幻灯片的索引,从 0 开始 number 0
    trigger 指示器的触发方式 string click
    autoplay 是否自动切换 boolean true
    interval 自动切换的时间间隔,单位为毫秒 number 3000
    indicator-position 指示器的位置 string outside/none
    arrow 切换箭头的显示时机 string always/hover/never hover
    type 走马灯的类型 string card
    事件名称说明回调参数
    change 幻灯片切换时触发 目前激活的幻灯片的索引,原幻灯片的索引
    方法名说明参数
    setActiveItem 手动切换幻灯片 需要切换的幻灯片的索引,从 0 开始;或相应 el-carousel-item 的 name 属性值
    prev 切换至上一张幻灯片
    next 切换至下一张幻灯片
    参数说明类型可选值默认值
    name 幻灯片的名字,可用作 setActiveItem 的参数 string
    label 该幻灯片所对应指示器的文本 string

     

  • 相关阅读:
    Advanced Configuration Tricks
    Reviewing the Blog Module
    Editing and Deleting Data
    Making Use of Forms and Fieldsets
    Understanding the Router
    SQL Abstraction and Object Hydration
    Preparing for Different Databases
    Java学习理解路线图
    Openstack学习历程_1_视频
    CentOS安装Nginx负载
  • 原文地址:https://www.cnblogs.com/grt322/p/8577858.html
Copyright © 2011-2022 走看看