本文实例为大家分享了微信小程序实现tab左右切换展示的具体代码,供大家参考,具体内容如下
分析
1.设置data-current属性用于:点击当前项时,通过点击事件swichNav中处理e.dataset.current取到点击的目标值。
2、swiper组件的current组件用于控制当前显示哪一页
3、swiper组件绑定change事件switchTab,通过e.detail.current拿到当前页
4、需要获取设备的宽度以及高度以便与导航栏切换的滑动
wxml:
<view class="container">
<!-- tab导航栏 -->
<!-- scroll-left属性可以控制滚动条位置 -->
<!-- scroll-with-animation滚动添加动画过渡 -->
<scroll-view scroll-x="true" class="nav" scroll-left="{
{navScrollLeft}}" scroll-with-animation="{
{true}}">
<block wx:for="{
{navData}}" wx:for-index="idx" wx:for-item="navItem" wx:key="idx">
<view class="nav-item {
{currentTab == idx ?'