
写的时候发现网上没有好用的,要么过于复杂,要么不太实用,我就自己整了个简单的
直接上代码部分
//wxml部分
<swiper indicator-dots="true" indicator-color="green" indicator-active-color="red" autoplay="true" interval="5000" duration="1000" circular="true" vertical="true">
<swiper-item wx:for="{{images}}">
<image src="{{item}}" mode="scaleToFill"></image>
</swiper-item>
</swiper>
下面是js部分,大部分都是自动生成的函数,只要在data里面存放图片地址就行,其他的可以不用管
// pages/template/template.js
Page({
/**
* 页面的初始数据
*/
data: {
images: ["/pages/template/images/1.png","/pages/template/images/2.png","/pages/template/images/3.png","/pages/template/images/4.png"]
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
效果图
iphone5表现效果
在这里插入图片描述
iphone 12/13 Pro Max表现效果
在这里插入图片描述
本人前端一般般,可能会有问题,仅供参考
1.使用touchstart、touchmove和touchend方法,在touchstart方法中,获取当前触点的位置,然后在touchmove方法中,通过比对当前触点位置和先前记录的触点位置,来判断用户是做左滑动还是右滑动;在touchend方法中,可以根据用户滑动的距离和滑动时间确定最终的滑动 *** 作,从而实现左右滑动功能。2.使用微信小程序APIswiper,可以在wxml中通过添加swiper元素来实现左右滑动。开发者只需要为swiper指定相关参数(如设置每屏显示的内容、滑动时显示的指示器等),就可以实现左右滑动的效果。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)