scroll-view

在这里插入图片描述
我们都知道点击tab按钮的时候,可以让scroll-view滑到指定的地方(scroll-into-view),但是手动滑到某个地方的时候,却不能反过来控制选中对应的tab,这时就只能自定义了

<scroll-view @scroll="scrolling" scroll-y="true" :scroll-with-animation="true" :scroll-into-view="valuescrollto"
		 :style="'height:'+cardscrollheight+'px;'">
</scroll-view>
scrolling(e) {
	if (!this.heightgot) {//在onshow或者mounted中获取不到滚动元素的高度或者获取的高度都是0,所以只能在这里获取,并且控制到只获取一次
		let query = uni.createSelectorQuery().in(this)
		let _this = this
		query.select('#itemindex0').boundingClientRect(data => {
			_this.onetotop = data.top
		}).exec();
		query.select('#itemindex1').boundingClientRect(data => {
			_this.twototop = data.top
		}).exec();
		query.select('#itemindex2').boundingClientRect(data => {
			_this.threetotop = data.top
		}).exec();
		query.select('#itemindex3').boundingClientRect(data => {
			_this.fourtotop = data.top
		}).exec();
		this.heightgot = true//保证只获取一次
	} else {
		if (this.aftertab) {//如果是点击了tab而产生的滚动,就不作处理
			this.aftertab = false
			return
		}
		if (e.detail.scrollTop < this.twototop - this.onetotop) {//手指滑动
			this.tabIndex = 0
		} else if (e.detail.scrollTop < this.threetotop - this.onetotop) {
			this.tabIndex = 1
		} else if (e.detail.scrollTop < this.fourtotop - this.onetotop) {
			this.tabIndex = 2
		} else {
			this.tabIndex = 3
		}
		this.valuescrollto = ''
	}
},
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值