您当前的位置: 首页 > 知识百科 > 微信小程序分页效果,小程序分页滑动效果怎么弄

微信小程序分页效果,小程序分页滑动效果怎么弄

时间:2023-07-01 14:05 阅读数:19 人阅读 分类:知识百科

  微信小程序分页效果有很多种,小编觉得最能吸引人的效果就是滑动效果,那么这个效果要怎么实现呢?一起来看看以下的教程,希望能够帮助到大家。

  功能:

  1.小程序分页栏与滑动视图绑定

  2.点击分页栏自动滑动到对应视图

  3.滑动的到视图对应分页栏自动显示选中导航栏样式

  效果图

  


  上代码

  wxml

  ?

  分页标签1

  分页标签2

  分页标签3

  autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" current="{{current}}" bindchange="swiperChange">

  wxss

  ?

  /*

  1.横向排列分页标签

  2.每个分页标签各占1/3

  */

  .tapNav {

  display: flex;

  flex-direction: row;

  }

  .tapNav view{

  flex:1;

  width:200rpx;

  height:100rpx;

  text-align: center;

  line-height: 100rpx;

  font-family: "微软雅黑";

  }

  /*选中样式*/

  .tapNav .active {

  color:blue;

  border-bottom:4rpx solid mediumseagreen;

  }

  #swiper {

  margin-top:40rpx;

  }

  #swiper image{

  width:100%;

  }

  js

  ?

  //index.js

  //获取应用实例

  var app = getApp()

  Page({

  data: {

  // 图片地址

  imgUrls: [

  'img02.tooopen/images/20150928/tooopen_sy_143912755726.jpg',

  'img06.tooopen/images/20160818/tooopen_sy_175866434296.jpg',

  'img06.tooopen/images/20160818/tooopen_sy_175833047715.jpg'

  ],

  //是否显示面板指示点

  indicatorDots: true,

  //自动播放

  autoplay: true,

  //切换时间间隔

  interval: 2000,

  //滑动时长

  duration: 1000,

  //存放滑动视图的current

  current:0,

  //分页标签class条件判断的值

  tabArr:{

  tabCurrentIndex:0

  }

  },

  //事件处理调用小程序函数

  //触摸分页标签触发事件

  veHandle:function(e){

  //每个分页标签都设置了data-index,触摸触发事件获取此数值

  //用此数值替换滑动视图的current

  //用此数值替换分页标签class判断的值

  console.log(e.target.dataset.index)

  var currentIndex = e.target.dataset.index

  this.setData({

  current:currentIndex,

  "tabArr.tabCurrentIndex":currentIndex

  })

  },

  //通过滑块视图的current改变触发事件

  swiperChange:function(e){

  //获取视图滑块当前的current

  //用此数值替换分页标签的current的值

  console.log(e.detail.current)

  var swiperCurrent = e.detail.current;

  this.setData({

  'tabArr.tabCurrentIndex':swiperCurrent

  })

  },

  onLoad: function () {

  console.log('onLoad')

  }

  })

  实现微信小程序分页效果其实并不难,尤其是滑动效果。把分页效果做得简单创意又有趣,那么你的小程序开发就已经成功了。想要获取更多资料请关注微信小程序素材网。

  

  微信公众号小程序的效果好吗?

  微信小程序滑动删除效果,微信小程序滑动删除实现代码

  关于微信小程序动画,微信小程序的动画效果