044_Carousel走马灯
1. Carousel走马灯
1.1. Carousel走马灯在有限空间内, 循环播放同一类型的图片、文字等内容。
1.2. Carousel Attributes
参数 |
说明 |
类型 |
可选值 |
默认值 |
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 |
无 |
loop |
是否循环显示 |
boolean |
无 |
true |
direction |
走马灯展示的方向 |
string |
horizontal/vertical |
horizontal |
1.3. Carousel Events
事件名称 |
说明 |
回调参数 |
change |
幻灯片切换时触发 |
目前激活的幻灯片的索引, 原幻灯片的索引 |
1.4. Carousel Methods
方法名 |
说明 |
参数 |
setActiveItem |
手动切换幻灯片 |
需要切换的幻灯片的索引, 从0开始; 或相应el-carousel-item的name属性值 |
prev |
切换至上一张幻灯片 |
无 |
next |
切换至下一张幻灯片 |
无 |
1.5. Carousel-Item Attributes
参数 |
说明 |
类型 |
可选值 |
默认值 |
name |
幻灯片的名字, 可用作setActiveItem的参数 |
string |
无 |
无 |
label |
该幻灯片所对应指示器的文本 |
string |
无 |
无 |
2. Carousel走马灯例子
2.1. 使用脚手架新建一个名为element-ui-carousel的前端项目, 同时安装Element插件。
2.2. 编辑index.js
import Vue from 'vue'
import VueRouter from 'vue-router'
import Carousel from '../components/Carousel.vue'
import OutsideCarousel from '../components/OutsideCarousel.vue'
import AlwaysArrowCarousel from '../components/AlwaysArrowCarousel.vue'
import CardCarousel from '../components/CardCarousel.vue'
import VerticalCarousel from '../components/VerticalCarousel.vue'Vue.use(VueRouter)const routes = [{ path: '/', redirect: '/Carousel' },{ path: '/Carousel', component: Carousel },{ path: '/OutsideCarousel', component: OutsideCarousel },{ path: '/AlwaysArrowCarousel', component: AlwaysArrowCarousel },{ path: '/CardCarousel', component: CardCarousel },{ path: '/VerticalCarousel', component: VerticalCarousel }
]const router = new VueRouter({routes
})export default router
2.3. 在components下创建Carousel.vue
<template><div><h1>基础用法</h1><h4>结合使用el-carousel和el-carousel-item标签就得到了一个走马灯。幻灯片的内容是任意的, 需要放在el-carousel-item标签中。默认情况下, 在鼠标hover底部的指示器时就会触发切换。通过设置trigger属性为click, 可以达到点击触发的效果。</h4><div><span>默认Hover指示器触发</span><el-carousel height="150px"><el-carousel-item v-for="item in 4" :key="item"><h3 class="small">{{ item }}</h3></el-carousel-item></el-carousel></div><div><span>Click指示器触发</span><el-carousel trigger="click" height="150px"><el-carousel-item v-for="item in 4" :key="item"><h3 class="small">{{ item }}</h3></el-carousel-item></el-carousel></div></div>
</template><style scoped>.el-carousel__item h3 {color: #475669;font-size: 14px;opacity: 0.75;line-height: 150px;margin: 0;}.el-carousel__item:nth-child(2n) {background-color: #99a9bf;}.el-carousel__item:nth-child(2n+1) {background-color: #d3dce6;}
</style>
2.4. 在components下创建OutsideCarousel.vue
<template><div><h1>指示器</h1><h4>indicator-position属性定义了指示器的位置。默认情况下, 它会显示在走马灯内部, 设置为outside则会显示在外部; 设置为none则不会显示指示器。</h4><el-carousel indicator-position="outside"><el-carousel-item v-for="item in 4" :key="item"><h3>{{ item }}</h3></el-carousel-item></el-carousel></div>
</template><style scoped>.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>
2.5. 在components下创建AlwaysArrowCarousel.vue
<template><div><h1>切换箭头</h1><h4>arrow属性定义了切换箭头的显示时机。默认情况下, 切换箭头只有在鼠标hover到走马灯上时才会显示; 若将arrow设置为always, 则会一直显示; 设置为never, 则会一直隐藏。</h4><el-carousel :interval="5000" arrow="always"><el-carousel-item v-for="item in 4" :key="item"><h3>{{ item }}</h3></el-carousel-item></el-carousel></div>
</template><style scoped>.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>
2.6. 在components下创建CardCarousel.vue
<template><div><h1>卡片化</h1><h4>将type属性设置为card即可启用卡片模式。从交互上来说, 卡片模式和一般模式的最大区别在于, 可以通过直接点击两侧的幻灯片进行切换。</h4><el-carousel :interval="4000" type="card" height="200px"><el-carousel-item v-for="item in 6" :key="item"><h3 class="medium">{{ item }}</h3></el-carousel-item></el-carousel></div>
</template><style scoped>.el-carousel__item h3 {color: #475669;font-size: 14px;opacity: 0.75;line-height: 200px;margin: 0;}.el-carousel__item:nth-child(2n) {background-color: #99a9bf;}.el-carousel__item:nth-child(2n+1) {background-color: #d3dce6;}
</style>
2.7. 在components下创建VerticalCarousel.vue
<template><div><h1>方向</h1><h4>默认情况下, direction为horizontal。通过设置direction为vertical来让走马灯在垂直方向上显示。</h4><el-carousel height="200px" direction="vertical" :autoplay="false"><el-carousel-item v-for="item in 3" :key="item"><h3 class="medium">{{ item }}</h3></el-carousel-item></el-carousel></div>
</template><style scoped>.el-carousel__item h3 {color: #475669;font-size: 14px;opacity: 0.75;line-height: 200px;margin: 0;}.el-carousel__item:nth-child(2n) {background-color: #99a9bf;}.el-carousel__item:nth-child(2n+1) {background-color: #d3dce6;}
</style>
2.8. 运行项目, 访问http://localhost:8080/#/Carousel
2.9. 运行项目, 访问http://localhost:8080/#/OutsideCarousel
2.10. 运行项目, 访问http://localhost:8080/#/AlwaysArrowCarousel
2.11. 运行项目, 访问http://localhost:8080/#/CardCarousel
2.12. 运行项目, 访问http://localhost:8080/#/VerticalCarousel
044_Carousel走马灯相关推荐
- [JQuery]用InsertAfter实现图片走马灯展示效果
写在前面 最近一个搞美工的朋友让我给他写一个图片轮播的特效. 需求: 图片向左循环滚动. 图片滚动到中间高亮显示,并在下方显示照片人物对应的信息. 鼠标悬停止滚动. 鼠标离开开始滚动. 单击图片,图片 ...
- 简单JS实现走马灯效果的文字(无需jQuery)
效果类似:(抱歉,图片是静态的) 写一段html,需要走马灯上下跳动的内容,但每次只显示一行: <hr size="0" align="center" s ...
- element ui走马灯怎么添加_Lovestu - Element UI 走马灯高度自适应
Element UI走马灯中,通过属性height来设置高度,但是设置就是死的,不能自适应.要自适应需要监控窗口宽度的变化. 网上别人分享的太复杂了,这儿有简单的方法实现高度自适应. 首先,确定图片的 ...
- 每天学一点flash(40) 制作走马灯四
在原来的基础上再增加多一个鼠标触发事件,那就是响应点击事件.当我们点击了每一张图片的时候那么我们就可以判断每一张所在连接图片的网址了.代码如下: package { import flash.dis ...
- element走马灯自动_Element Carousel 走马灯的具体实现
本文来源于Element官方文档: 基础用法 普通走马灯 默认 Hover 指示器触发 {{ item }} Click 指示器触发 {{ item }} 组件- 走马灯 基础用法 默认 Hover ...
- android 走马灯效果
最进其实自己也没什么想写的内容,不过自己觉得还是需要每天写点东西,好的习惯还是要保持的.所以今天讲讲textview的文字显示走马灯的效果,这个实在太简单了. 项目开发中有些时候TextView的文本 ...
- iview的走马灯嵌套在模态框中,宽度为0的解决方案
在项目开发中用到了iview的走马灯嵌套在模态框中这种需求,结果发现走马灯图片不显示,打开控制台审查元素发现走马灯的内部盒子width为0,自己感觉在页面初始化的时候,因为模态框初始值为false,所 ...
- iPhone走马灯控件实现
走马灯效果实现原理,就是利用iPhone自带的动画来控制UILable的y轴位置: 代码如下: 代码 //LampText.h @interface LampText : UILabel { ...
- html跑马灯可以上下动ma,使用 JS 实现上下滚动走马灯
?前言 今天在做商城首页时,遇到一个上下走马灯功能,因为之前也只是接触过左右的走马灯,一时还不知道从何下手.在网上看了几个 demo,并亲自运行了一下,是可以实现的.但是,能运行不知其所以然也不行,所 ...
最新文章
- linux 变量替换字符串,变量替换 字符串处理
- 【C++】多线程与原子操作和无锁编程【五】
- Android Input系统之触摸屏
- 【Android 逆向】Android 权限 ( adb 降权相关的属性 | ro.secure 属性 | ro.debuggable 属性 | service.adb.root 属性 )
- zabbix icmp ping 监控主机_Zabbix监控 MySQL 性能
- 一步一步封装自己的HtmlHelper组件:BootstrapHelper
- 【原创】rabbitmq-echopid用户手册(翻译)
- c# emnu 获取注释_C#机器学习之判断日报是否合格
- 了解IHttpModule接口事件执行顺便 获取Session
- 【C语言】冒泡排序法
- 成人高考专升本- 你需要知道的事情!!
- activity劫持反劫持
- 左耳朵耗子:996不是福气,但努力就会成功么?
- Git+Vscode+ToroiseGit+码云
- 联阿里接腾讯,B站如何实现“意义非凡”的一年
- 阿里云创建docker免费个人容器镜像托管(私服)服务
- 小尾巴微博html5版,小尾巴
- 545C - Woodcutters
- Java实现 LeetCode 54 螺旋矩阵
- 微信h5支付在iframe弹窗的坑