微信小程序之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>
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;
}
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
})
},
})
当点击"立即体验",会有一个弹窗提示。
本文参考链接:
https://blog.csdn.net/xiangzhihong8/article/details/80645094
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· 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的事件绑定和解绑,事件委托(事件代理))