小程序自定义tab,tapItem 居中

使用到 scroll-view

html

	<scroll-view scroll-x='true'  scroll-left="{{moveWidth}}" scroll-with-animation="true">
		<view class="sroll">
			<view class="weeks {{currentDay == index? 'activeWeeks':''}}"  
				wx:for="{{weeks}}" wx:key="index"  id="{{index}}"
				data-day="{{item.time}}" bindtap="selectDays" >
				{{item.day}}({{item.time}})
				<text wx:if="{{isfull}}">text>
			view>
		view>
	scroll-view>

js

selectDays(e){
		let currentDay = e.currentTarget.id
		let day = e.currentTarget.dataset.day
		let moveWidth 
		//因为tabitem的长度不是固定不变了,为了每次点击之后能够正常看到前一个和后一个tabItem,所以我传值也是不一样
		if(currentDay <2){
			moveWidth = currentDay * 10
		}else if(currentDay < 4){
			moveWidth = currentDay * 80
		}else {
			moveWidth = currentDay * 100
		}
		
	
		this.setData({currentDay,moveWidth})
	},


你可能感兴趣的:(前端知识)