微信小程序如何在 wx:for 中判断页面跳转
18
2024-10-17
这篇文章主要介绍了微信小程序滚动tab实现左右可滑动切换的相关资料,这里提供实现实例帮助大家实现这样的功能,需要的朋友可以参考下
微信小程序滚动Tab实现左右可滑动切换
效果:
最终效果如上。问题:
1、tab标题总共8个,所以一屏无法全部显示。
2、tab内容区左右滑动切换时,tab标题随即做标记(active)。
3、当active的标题不在当前屏显示时,要使其能显示到当前屏中。
一、wxml结构
tab标题因一排八个,所以使用 scroll-view组件,使其可横向滚动。
tab内容可左右滑动切换,使用swiper组件实现
为了偷懒,所以数据都通过wx:for遍历重复出来。
说明:
1、设置data-current属性用于:点击当前项时,通过点击事件swichNav中处理e.dataset.current取到点击的目标值。
2、swiper组件的current组件用于控制当前显示哪一页
3、swiper组件绑定change事件switchTab,通过e.detail.current拿到当前页
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
二、js部分
微信小程序在开发起来,个人感觉挺像vue的,以数据驱动视图的更新。所以在小程序中,不能直接操作dom,当然也不能使用jquery之类的库。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
三、wxss样式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
以上就是微信小程序滚动Tab如何实现左右可滑动切换的实例分析的详细内容。
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~