微信小程序--动态切换栏
2021-01-28 15:35
549 查看
效果展示
Demo代码
wxml
<!-- 切换栏 --> <view class='list-top'> <ul> <li class="{{flag==0?'active':''}}" catchtap="changeflag" data-index="0">打卡记录</li> <li class="{{flag==1?'active':''}}" catchtap="changeflag" data-index="1">月排行榜</li> <li class="{{flag==2?'active':''}}" catchtap="changeflag" data-index="2">总排行榜</li> </ul> </view> <!-- 对于swiper --> <swiper class='swiper-1' current="{{flag}}" indicator-dots="{{swiper.indicatorDots}}" autoplay="{{swiper.autoplay}}" interval="{{swiper.interval}}" duration="{{swiper.duration}}" bindchange="changeSlider"> <block> <!-- 第一个栏目 --> <swiper-item> <image src="https://wx1.sinaimg.cn/large/691bee7aly1gbr3vrg2ceg20m80gok5e.gif"></image> </swiper-item> <!-- 第二个栏目 --> <swiper-item> <image src="https://wx1.sinaimg.cn/large/691bee7aly1gbr3vsnljog20m80gogul.gif"></image> </swiper-item> <!-- 第三个栏目 --> <swiper-item> <image src="https://wx1.sinaimg.cn/large/691bee7aly1gbr3vp6f91g20m80gok11.gif"></image> </swiper-item> </block> </swiper>
js
//index.js //获取应用实例 const app = getApp() Page({ data: { flag: 0, //状态栏切换 swiper: { indicatorDots: false, autoplay: false, interval: 5000, duration: 1000 }, //swiper设置 }, onLoad: function () { }, changeflag: function (e) { var k = this k.setData({ flag: e.target.dataset.index }) console.log(e.target.dataset.index) }, changeSlider: function (e) { var k = this this.setData({ flag: e.detail.current }) console.log(e.detail.current) }, })
wxss
完整源码获取途径 见文末引言```
相关文章推荐
- 微信小程序——动态切换class以及bindtap事件
- 微信小程序动态切换class类名
- 微信小程序之tab切换效果
- 为什么微信小程序使用wx.chooseImage上传 gif动态图被自动转成了 jpeg图片了?
- 微信小程序 —— 动态决定页面元素显示或隐藏的技巧
- 微信小程序 Tab页切换更新数据
- 微信小程序通过js动态获取节点信息
- 微信小程序 动态改变样式
- 微信小程序开发常用技巧(5)——view左右滑动,切换page页面
- 在单文档程序中动态切换多个窗体的源码程序
- 微信小程序小技巧系列《一》幻灯片,tab导航切换
- 在单文档程序中动态切换多个窗体
- 【微信小程序开发】快速开发一个动态横向导航模板并使用
- 微信小程序实现tab和swiper切换结合效果
- 微信小程序之view动态布局
- 小程序组件-swipe多页切换,并支持下拉刷新,上拉加载,menu动态联动切换
- 微信小程序外卖选购页实现切换分类与数量加减功能案例
- 详解微信小程序Radio选中样式切换
- 微信小程序点击切换图片
- 转载!!!微信小程序中初始化完成自动切换到设定的tab页