【Kevin Learn 小程序】-->swiper

效果图

在这里插入图片描述

属性

参考:swiper

实例

  1. app.js
//app.js
App({
  onLaunch: function () {
    console.log('App Launch')
  },
  onShow: function () {
    console.log('App Show')
  },
  onHide: function () {
    console.log('App Hide')
  },
  globalData: {
    hasLogin: false
  }
})
  1. app.json
{
  "pages": [
    "pages/swiper/swiper"
  ],
  "window": {
    "backgroundTextStyle": "light",
    "navigationBarBackgroundColor": "#fff",
    "navigationBarTitleText": "WeChat",
    "navigationBarTextStyle": "black"
  },
  "style": "v2",
  "sitemapLocation": "sitemap.json"
}
  1. swiper.wxml
<!--pages/swiper/swiper.wxml-->
<view>swiper组件</view>
<view class="section">
    <view class="page-body">
        <view class="page-section page-section-spacing swiper">
            <swiper 
                indicator-dots="{{indicatorDots}}" 
                autoplay="{{autoplay}}" 
                interval="{{interval}}"
                duration="{{duration}}"
                bindchange="change"
                bindanimationfinish="animationfinish"
            >   
                <block wx:for="{{background}}" wx:key="*this">
                    <swiper-item>
                        <view class="swiper-item {{item}}"></view>
                    </swiper-item>
                </block>
            </swiper>
        </view>
        <view class="page-section" style="margin-top: 40rpx;margin-bottom: 0;">
            <view class="weui-cells weui-cells_after-title">
                <view class="weui-cell weui-cell_switch">
                    <view class="weui-cell__bd">指示点</view>
                    <view class="weui-cell__ft">
                        <switch checked="{{indicatorDots}}" bindchange="changeIndicatorDots" />
                    </view>
                </view>
                <view class="weui-cell weui-cell_switch">
                    <view class="weui-cell__bd">自动播放</view>
                    <view class="weui-cell__ft">
                        <switch checked="{{autoplay}}" bindchange="changeAutoplay" />
                    </view>
                </view>
            </view>
        </view>

        <view class="page-section page-section-spacing">
            <view class="page-section-title">
                <text>幻灯片切换时长(ms)</text>
                <text class="info">{{duration}}</text>
            </view>
            <slider bindchange="durationChange" value="{{duration}}" min="500" max="2000" />
            <view class="page-section-title">
                <text>自动播放间隔时长(ms)</text>
                <text class="info">{{interval}}</text>
            </view>
            <slider bindchange="intervalChange" value="{{interval}}" min="2000" max="10000" />
        </view>
    </view>
</view>

  1. swiper.wxss
/* pages/swiper/swiper.wxss */
button{
  margin-bottom: 30rpx;
}
button:last-child{
  margin-bottom: 0;
}
.page-body {
    width: 100%;
}
.page-section-title{
  padding: 0;
}
.swiper-item{
  display: block;
  height: 150px;

}
.page-section-title{
  margin-top: 60rpx;
  position: relative;
}
.info{
  position: absolute;
  right: 0;
  color: #353535;
  font-size: 30rpx;
}
.page-foot{
  margin-top: 50rpx;
}
.demo-text-1{
  position: relative;
  align-items: center;
  justify-content: center;
  background-color: #1AAD19;
  color: #FFFFFF;
  font-size: 36rpx;
}
.demo-text-1:before{
  content: 'A';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.demo-text-2{
  position: relative;
  align-items: center;
  justify-content: center;
  background-color: #2782D7;
  color: #FFFFFF;
  font-size: 36rpx;
}
.demo-text-2:before{
  content: 'B';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.demo-text-3{
  position: relative;
  align-items: center;
  justify-content: center;
  background-color: #F1F1F1;
  color: #353535;
  font-size: 36rpx;
}
.demo-text-3:before{
  content: 'C';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
  1. swiper.js
Page({
  data: {
    background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
    indicatorDots: true,
    vertical: false,
    autoplay: false,
    interval: 2000,
    duration: 300
  },
  /**
   * swiper api
   */
  changeIndicatorDots: function (e) {
    console.log('切换指示点开关');
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
  changeAutoplay: function (e) {
    console.log('切换自动播放开关');
    this.setData({
      autoplay: !this.data.autoplay
    })
  },
  intervalChange: function (e) {
    console.log(`调整自动播放间隔时长为: ${e.detail.value}ms`);
    this.setData({
      interval: e.detail.value
    })
  },
  durationChange: function (e) {
    console.log(`调整幻灯片切换时长为: ${e.detail.value}ms`);
    this.setData({
      duration: e.detail.value
    })
  },
  animationfinish: function (e) {
    console.log(e);
  },
  change: function (e) {
    console.log(e)
  }
})
  1. swiper.json
{
  "navigationBarTitleText": "swiper组件"
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Kevin-Dev

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值