微信小程序学习笔记——常见组件【swiper】

swiper

滑块视图容器。其中只可放置swiper-item组件,否则会导致未定义的行为。

常用属性 

autoplay 自动轮播

interval 修改轮播时间

circular 衔接轮播

indicator-dots 显示 指示器 分页器 索引器

indicator-color 指示器的未选择时的颜色

indicator-active-color 指示器的选中时的颜色

属性类型默认值必填说明最低版本
indicator-dotsbooleanfalse是否显示面板指示点1.0.0
indicator-colorcolorrgba(0, 0, 0, .3)指示点颜色1.1.0
indicator-active-colorcolor#000000当前选中的指示点颜色1.1.0
autoplaybooleanfalse是否自动切换1.0.0
currentnumber0当前所在滑块的 index1.0.0
intervalnumber5000自动切换时间间隔【常用】1.0.0
durationnumber500滑动动画时长   【常用】1.0.0
circularbooleanfalse是否采用衔接滑动  【是否循环播放】【常用】1.0.0
verticalbooleanfalse滑动方向是否为纵向1.0.0
previous-marginstring"0px"前边距,可用于露出前一项的一小部分,接受 px 和 rpx 值1.9.0
next-marginstring"0px"后边距,可用于露出后一项的一小部分,接受 px 和 rpx 值1.9.0
display-multiple-itemsnumber1同时显示的滑块数量1.9.0
skip-hidden-item-layoutbooleanfalse是否跳过未显示的滑块布局,设为 true 可优化复杂情况下的滑动性能,但会丢失隐藏状态滑块的布局信息1.9.0
easing-functionstring"default"指定 swiper 切换缓动动画类型2.6.5
bindchangeeventhandlecurrent 改变时会触发 change 事件,event.detail = {current, source}1.0.0
bindtransitioneventhandleswiper-item 的位置发生改变时会触发 transition 事件,event.detail = {dx: dx, dy: dy}2.4.3
bindanimationfinisheventhandle动画结束时会触发 animationfinish 事件,event.detail 同上1.9.0

easing-function 的合法值

说明最低版本
default默认缓动函数
linear线性动画
easeInCubic缓入动画
easeOutCubic缓出动画
easeInOutCubic缓入缓出动画

change事件 source 返回值

从 1.4.0 开始,change事件增加 source字段,表示导致变更的原因,可能值如下:

  1. autoplay 自动播放导致swiper变化;
  2. touch 用户划动引起swiper变化;
  3. 其它原因将用空字符串表示。

等比例计算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  高度为原图的高度

<!-- 
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
 
 -->
<swiper autoplay interval="3000" circular indicator-dots indicator-color='#0094ff' indicator-active-color="#ff0094">
    <swiper-item>
        <image mode="widthFix" src="//m.360buyimg.com/mobilecms/s700x280_jfs/t1/113023/15/586/97530/5e8e85e5E1964d56c/70c5a8cd4d2d8d1a.jpg!cr_1125x445_0_171!q70.jpg.dpg" alt="" />
    </swiper-item>
    <swiper-item>
        <image mode="widthFix" src="//m.360buyimg.com/mobilecms/s700x280_jfs/t1/114669/38/1013/108609/5e93db07E85fb0d3b/000f8e8598187f7e.jpg!cr_1125x445_0_171!q70.jpg.dpg" alt="" />
    </swiper-item>
    <swiper-item>
        <image mode="widthFix" src="//m.360buyimg.com/mobilecms/s700x280_jfs/t1/95842/38/12546/80187/5e4ba3e7E09e0da3b/92aac67aefdf6b6f.jpg!cr_1125x445_0_171!q70.jpg.dpg" alt="" />
    </swiper-item>
</swiper>
  
/* pages/swiperPage/swiperPage.wxss */
swiper{
  width: 100%;
  height: calc(100vw * 277 / 700);
}
image{
  width: 100%;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值