微信小程序实现垂直tab标签页的切换及动态的选中下划线移动-纵向

微信小程序实现垂直tab标签页的切换及动态的选中下划线移动

注意:当前是纵向切换,横向切换请点击:横向切换tab

效果演示

在这里插入图片描述

代码片段

代码段链接如下:
纵向切换tab代码片段
可直接点击代码片段路径观看完整演示。

完整代码

wxml如下
<view class="cont" style="height: {{allHeight}}rpx;">
    <scroll-view class="lf" style="height: {{allHeight}}rpx;" scroll-y bindscroll="viewscroll" scroll-into-view="lf{{i}}" scroll-with-animation>
        <view class="contline" style="top: {{conttop}}px;"></view>
        <view class="item {{item.id == i ? 'active' : ''}}" wx:for="{{list}}" id="lf{{item.id}}" wx:key="index" data-id="{{item.id}}" bindtap="clicklf">{{item.name}}</view>
    </scroll-view>
	<swiper current="{{cate_id}}" vertical="{{true}}" class="swiper_cont">
		<swiper-item wx:for="{{list}}" item-id="{{item.id}}" wx:key="id">
			<scroll-view class="rf" style="height: {{allHeight}}rpx;" scroll-y enable-back-to-top='true' bindscrolltolower="loadmore" scroll-top="{{top}}">
				{{item.name}}
			</scroll-view>
		</swiper-item>
	</swiper>
</view>
wxss如下
page{ width: 100%; height: 100%;}
.cont{ display: flex; width:100%; height: 100%;}
.cont .swiper_cont{ flex: 1 1 0; height: 100%; overflow: hidden;}
.cont .swiper_cont swiper-item{ background-color: #FFAEC9;}
.cont .swiper_cont swiper-item:nth-child(2n){ background-color: #99D9EA;}
.cont .lf{width:165rpx;overflow:auto;font-size:28px;background:#EAECF1;-webkit-overflow-scrolling: touch}
.cont .lf .item{line-height:79rpx;text-align: center;color:#666;font-weight:normal;position:relative;font-size: 28rpx;}
.cont .lf .item.active{color:#000!important;background:#fff;font-weight:bold}
.cont .rf{flex:1 1 0; color: #fff; text-align: center; line-height: 180rpx; overflow:auto; -webkit-overflow-scrolling: touch}
.contline{width:5rpx;height:29rpx;background:#FF3742;position:absolute;left:0;top:25rpx;z-index:9;transition:all .8s}
js如下
Page({
	data: {
		list: [
			{ name: '热门', id: 0},
			{ name: '上衣女', id: 1},
			{ name: '上衣男', id: 2},
			{ name: 'T恤', id: 3},
			{ name: '短裙', id: 4},
			{ name: '长裙', id: 5},
			{ name: '连衣裙', id: 6},
			{ name: '夏季凉鞋', id: 7},
			{ name: '冬季短靴', id: 8},
			{ name: '包包饰品', id: 9},
			{ name: '休闲裤', id: 10},
			{ name: '西装', id: 11},
		],
		i: 0,
		id:null,
		top: 0,
		scrollTop: 0,
		page: 1,
		nomore: false,
		stopLoadingmoreTiem: false,
	},
	onLoad(){
		let _this = this;
        wx.getSystemInfo({
            success: function (res) {
                _this.setData({
                    allHeight: res.windowHeight * 750 / res.windowWidth
                })
            }
        })
	},
	clicklf(e){
		let _this = this,
			i = e.currentTarget.dataset.id,
            lasttop = parseInt(_this.data.lasttop),
            scrollTop = parseInt(_this.data.scrollTop);
        this.setData({
            i: i,
            nomore: false,
            top: 0,
            id: i,
            cate_id: i
        })
        wx.createSelectorQuery().select('.cont .lf .item.active').boundingClientRect(rect => {
            _this.setData({
                conttop: rect.top + scrollTop + 12 - lasttop
            })
        }).exec()
        //在这里请求接口获取数据
    },
    viewscroll(e){
        this.setData({
            scrollTop: e.detail.scrollTop
        })
	},
	onShow: function () {
        let _this = this,
            lasttop = _this.data.lasttop;
        wx.createSelectorQuery().select('.cont .active').boundingClientRect(rect => {
            // console.log(rect);
            lasttop = rect.top;
            _this.setData({
                lasttop: lasttop
            })
        }).exec();
    }
})
  • 2
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天外来鹿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值