微信小程序之Swiper组件

一、概述

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

官方文档:https://developers.weixin.qq.com/miniprogram/dev/component/swiper.html

 

二、Swiper实现引导页

在移动开发中,我们经常使用ViewPager(Android)和UIScrollView(ios)来实现引导页面,效果如下。

 

test.wxml

复制代码
<swiper indicator-active-color='#fff' indicator-dots="true" indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}"
  interval="{{interval}}" duration="{{duration}}">
  <block wx:for="{{imgs}}" wx:for-index="index" wx:key="swiperItem" wx:for-item="item">
    <swiper-item class="swiper-items">
      <image class="swiper-image" src="{{item}}"></image>
      <button class="button-img" bindtap="start" wx:if="{{index == imgs.length - 1}}">立即体验</button>
    </swiper-item>
  </block>
</swiper>
View Code
复制代码

 

test.wxss

复制代码
swiper {
  position: absolute;
  height: 100%;
  width: 100%;
}

.swiper-image {
  height: 100%;
  width: 100%;
  opacity:0.9;
}

.button-img{   
   position: relative;
   bottom: 120px;
   height: 40px;
   width: 120px;
   opacity:0.6;
}
View Code
复制代码

 

test.js

复制代码
Page({
  data: {
    imgs: [
      "https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2522069454.jpg",
      "https://img1.doubanio.com/view/photo/s_ratio_poster/public/p2522778567.jpg",
      "https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2523516430.jpg",
    ],

    img: "http://img.kaiyanapp.com/7ff70fb62f596267ea863e1acb4fa484.jpeg",
    duration: 2000, // 滑动动画时长
    indicatorDots: true, // 是否显示指示点
    autoplay: true, // 是否自动切换
    interval: 3000, // 自动切换时间间隔
  },
  start: function () {
    wx.showToast({
      title: '该功能未上线!',
      icon: 'none',
      duration: 1500
    })
  },
})
View Code
复制代码

 

当点击"立即体验",会有一个弹窗提示。

 

 

本文参考链接:

https://blog.csdn.net/xiangzhihong8/article/details/80645094

 

posted @   肖祥  阅读(637)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
历史上的今天:
2020-06-04 使用Python登录网关设备执行命令
2018-06-04 python 全栈开发,Day55(jQuery的位置信息,JS的事件流的概念(重点),事件对象,jQuery的事件绑定和解绑,事件委托(事件代理))
点击右上角即可分享
微信分享提示