属性名 类型 默认值 说明
indicator-dots Boolean false 是否显示面板指示点
autoplay Boolean false 是否自动切换
current Number 0 当前所在页面的 index
interval Number 5000 自动切换时间间隔
duration Number 1000 滑动动画时长
bindchange EventHandle   current 改变时会触发 change 事件,event.detail = {current: current}
 
注意:其中只可放置<swiper-item/>组件,其他节点会被自动删除。
swiper-item
仅可放置在<swiper/>组件中,宽高自动设置为100%。
 
<view class="page">
  <view class="page__hd">
    <text class="page__title">swiper</text>
    <text class="page__desc">swiper</text>
  </view>
  <view class="page__bd">
    <view class="section section_gap swiper">
        <swiper indicator-dots="{{indicatorDots}}" vertical="{{vertical}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}">
            <block wx:for="{{background}}">
                <swiper-item>
                  <view class="swiper-item bc_{{item}}"></view>
                </swiper-item>
            </block>
        </swiper>
    </view>
    <view class="btn-area">
      <button type="default" bindtap="changeIndeicatoirDots">indicator-dots</button>
      <button type="default" bindtap="changeVertical"> {{vertical?'horizontal':'vertical'}}</button>
      <button type="default" bindtap="changeAutoplay">autoplay</button>
    </view>
    <slider bindchange="durationChange" value="{{duration}}" show-value min="500" max="2000" />
    <view class="section__title">duration</view>
    <slider bindchange="intervalChange" value="{{interval}}" show-value min="2000" max="10000" />
    <view class="section__title">interval</view>
  </view>
</view>
 
Page({
  data:{
    background:['green','red','yellow'],
    indicatorDots:true,
    vertical:false,
    autoplay:true,
    interval:3000,
    duration:1200
  },
  changeIndeicatoirDots : function (e) {
    this.setData({
      indicatorDots : !this.data.indicatorDots
    })
  },
  changeVertical : function (e) {
    this.setData({
      vertical: !this.data.vertical
    })
  },
  changeAutoplay: function (e){
    this.setData({
      autoplay:!this.data.autoplay
    })
  },
  durationChange: function (e){
    this.setData({
        duration:e.detail.value
    })
  },
  intervalChange: function (e) {
    this.setData({
      interval:e.detail.value
    })
  }
})

item单击事件

在 swiper-item 上绑定事件,通过 data 自定义标签绑定数据。然后在function中通过event拿到。
<!--main.wxml-->
<view>
<swiper class="swiper_box" indicator-dots="{{indicatorDots}}" vertical="{{vertical}}"
autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" bindchange="swiperchange">
<block wx:for="{{images}}">
<swiper-item bindtap="itemclick" data-id="{{item.id}}" data-name="{{item.name}}">
<image src="{{item.picurl}}" class="slide-image"/>
</swiper-item>
</block>
</swiper>
</view>
1234567891011
注意代码中的 data-id 和 data-name 均为自定义标签,然后可以在绑定事件的event中通过 id 和 name 拿到。
// 轮播item点击事件
itemclick: function(e) {
wx.showToast({
title: e.currentTarget.dataset.id + "",
icon: 'success',
duration: 2000
})
},
12345678
注意在绑定的function中可以通过event拿到对应的数据。如:e.currentTarget.dataset.id 对应wxml中的data-id
 
当然,还有另一种办法。不需要绑定事件,通过在每一个的 swiper-item 外面包上一个 a 标签,以超链接的方式跳转页面。
 

滑块视图容器   swiper的更多相关文章

  1. 小程序开发基础-swiper 滑块视图容器

    小编 / 达叔小生 参考官方文档:https://developers.weixin.qq.com/miniprogram/dev/component/ 小程序开发基础-swiper 滑块视图容器 根 ...

  2. 小程序swiper 滑块视图容器

    属性名 类型 默认值 说明 最低版本 indicator-dots Boolean false 是否显示面板指示点 indicator-color Color rgba(0, 0, 0, .3) 指示 ...

  3. 微信小程序之视图容器(swiper)组件创建轮播图

    一.视图容器(Swiper) 1.swiper:滑块视图容器 微信官方文档:https://developers.weixin.qq.com/miniprogram/dev/component/swi ...

  4. 微信小程序组件解读和分析:三、swiper滑块视图

    swiper滑块组件说明: 滑块视图容器,用于展示图片,可以通过用户拖拽和设置自动切换属性控制图片的切换   组件的使用示例的运行效果如下: 下面是WXML代码: [XML] 纯文本查看 复制代码 ? ...

  5. 微信小程序-视图容器组件

    view 视图容器 例如: <view class="section"> <view class="section__title">fl ...

  6. 微信小程序-组件-视图容器

    1.view 1.作用:类似 html 的 div 用来进行页面布局,具有块级盒子特性. 2.常用属性:设置view盒子点击后的状态,以及控制是否影响父盒子的点击状态 3.eg:<view ho ...

  7. 小程序开发基础-view视图容器

    view 视图容器. // wxml <view class="section"> <view class="section__title"& ...

  8. 微信小程序组件解读和分析:一、view(视图容器 )

    view组件说明:    视图容器    跟HTML代码中的DIV一样,可以包裹其他的组件,也可以被包裹在其他的组件内部.用起来比较自由随意,没有固定的结构. view组件的用法: 示例项目的wxml ...

  9. 微信小程序之可滚动视图容器组件 scroll-view

    1. 纵向滚动 scroll-y 当 设置为scroll-y 时, 需要将其高度设为固定值 如果整个页面,即最外层标签为scroll-view,需要并将其高度设为100%,也需要将page设为100% ...

随机推荐

  1. 杂谈1.py

    Python命名规则: 1. 组成:数字/字母/下划线 只能以字母,下划线开头 不能包含空格 避免Python关键字和函数名 简短且具有描述性 描述数据形态及支持操作 Python动态类型 变量无类型 ...

  2. vue+窗格切换+田字+dicom显示_03

    环境:vue+webpack+cornerstone ide:vs code 需求:窗格设置+拼图设置 代码: 主体:printPage.vue <div class="div mid ...

  3. 爬虫基础线程进程学习-Scrapy

    性能相关 学习参考:http://www.cnblogs.com/wupeiqi/articles/6229292.html 在编写爬虫时,性能的消耗主要在IO请求中,当单进程单线程模式下请求URL时 ...

  4. jmeter压测之添加负载机

    jmeter压测基本介绍一般基准测试(基准测试时间一般为5分钟)后压测的时间是10-15分钟: 实施测试之前要拿到测试指标 例如:tps要达到多少响应时间要达到多少并发数要达到多少TPS :服务端每秒 ...

  5. 剑指offer例题——反转链表

    题目描述 输入一个链表,反转链表,输出新链表的表头 程序编写 将链表反转 public class Solution { public ListNode ReverseList(ListNode he ...

  6. 前端 跨Area后Cookie无法访问

    创建两个区域,一个是User,一个是Manage. User区域有两个页面,index1,和index2 User区域: index1:负责写入cookie index2:负责读取cookie Man ...

  7. centos7下面添加htop工具

    htop下载wget http://sourceforge.net/projects/htop/files/latest/download 解压tar -zxf downloadcd htop-1.0 ...

  8. ajax请求导致status为canceled(无任何回调数据)的原因

    1.故障现象 一个普通的ajax请求,请求能够到达controller,也能正常处理业务,但是ajax的回调函数为空,即没有任何状态和数据返回,使用谷歌浏览器查看请求状态如下图: 出现该错误:简单来说 ...

  9. Linux - 操作系统

    操作系统(科普章节) 目标 了解操作系统及作用 1. 操作系统(Operation System,OS) 操作系统作为接口的示意图 没有安装操作系统的计算机,通常被称为 裸机 如果想在 裸机 上运行自 ...

  10. 解决在jupyter notebook中遇到的ImportError: matplotlib is required for plotting问题

    昨天学习pandas和matplotlib的过程中, 在jupyter notebook遇到ImportError: matplotlib is required for plotting错误, 以下 ...