微信小程序学习笔记——常见组件【swiper】
swiper 滑块视图容器。其中只可放置swiper-item组件,否则会导致未定义的行为。
常用属性
autoplay 自动轮播
interval 修改轮播时间
circular 衔接轮播
indicator-dots 显示 指示器 分页器 索引器
【微信小程序学习笔记——常见组件【swiper】】indicator-color 指示器的未选择时的颜色
indicator-active-color 指示器的选中时的颜色
属性 | 类型 | 默认值 | 必填 | 说明 | 最低版本 |
---|---|---|---|---|---|
indicator-dots | boolean | false | 否 | 是否显示面板指示点 | 1.0.0 |
indicator-color | color | rgba(0, 0, 0, .3) | 否 | 指示点颜色 | 1.1.0 |
indicator-active-color | color | #000000 | 否 | 当前选中的指示点颜色 | 1.1.0 |
autoplay | boolean | false | 否 | 是否自动切换 | 1.0.0 |
current | number | 0 | 否 | 当前所在滑块的 index | 1.0.0 |
interval | number | 5000 | 否 | 自动切换时间间隔【常用】 | 1.0.0 |
duration | number | 500 | 否 | 滑动动画时长【常用】 | 1.0.0 |
circular | boolean | false | 否 | 是否采用衔接滑动【是否循环播放】【常用】 | 1.0.0 |
vertical | boolean | false | 否 | 滑动方向是否为纵向 | 1.0.0 |
previous-margin | string | "0px" | 否 | 前边距,可用于露出前一项的一小部分,接受 px 和 rpx 值 | 1.9.0 |
next-margin | string | "0px" | 否 | 后边距,可用于露出后一项的一小部分,接受 px 和 rpx 值 | 1.9.0 |
display-multiple-items | number | 1 | 否 | 同时显示的滑块数量 | 1.9.0 |
skip-hidden-item-layout | boolean | false | 否 | 是否跳过未显示的滑块布局,设为 true 可优化复杂情况下的滑动性能,但会丢失隐藏状态滑块的布局信息 | 1.9.0 |
easing-function | string | "default" | 否 | 指定 swiper 切换缓动动画类型 | 2.6.5 |
bindchange | eventhandle | 否 | current 改变时会触发 change 事件,event.detail = {current, source} | 1.0.0 | |
bindtransition | eventhandle | 否 | swiper-item 的位置发生改变时会触发 transition 事件,event.detail = {dx: dx, dy: dy} | 2.4.3 | |
bindanimationfinish | eventhandle | 否 | 动画结束时会触发 animationfinish 事件,event.detail 同上 | 1.9.0 |
值 | 说明 | 最低版本 |
---|---|---|
default | 默认缓动函数 | |
linear | 线性动画 | |
easeInCubic | 缓入动画 | |
easeOutCubic | 缓出动画 | |
easeInOutCubic | 缓入缓出动画 |
change
事件 source
返回值 从 1.4.0 开始,change
事件增加 source
字段,表示导致变更的原因,可能值如下:autoplay
自动播放导致swiper变化;touch
用户划动引起swiper变化;- 其它原因将用空字符串表示。
等比例计算swiper高度
1. 轮播图的外层容易 swiper
2. 每一个轮播项 swiper-item
3. swiper便签中 存在默认样式
width 100%
height 150px
image 存在默认宽高 320*240
swiper无法实现由内容撑开
4. 先找出来 原图的宽高, 等比例给swiper定宽高
原图的宽度和高度700 * 277(原图是京东官网的轮播图)
swiper宽度/swiper高度 = 原图的宽度/原图的高度
swiper高度 = swiper宽度 * 原图高度 / 原图宽度
height:750rpx*277/700或者100vm*277/700
5. 也可以做如下的处理和上面的处理效果一样
原图 640px * 200px
让图片高度自适应 宽度100%mode="widthFix"
让swiper宽度为750rpx高度为原图的高度



/* pages/swiperPage/swiperPage.wxss */
swiper{
width: 100%;
height: calc(100vw * 277 / 700);
}
image{
width: 100%;
}
推荐阅读
- 一个小故事,我的思考。
- 家乡的那条小河
- 一个人的碎碎念
- 野营记-第五章|野营记-第五章 讨伐梦魇兽
- 昨夜小楼听风
- 2021-02-17|2021-02-17 小儿按摩膻中穴-舒缓咳嗽
- 基于微信小程序带后端ssm接口小区物业管理平台设计
- 2019.4.18感恩日记
- 那件我们忽略的小事叫感恩
- 你有婚内虐待行为吗()