微信小程序scroll-top事件和bindscroll事件冲突
<scroll-view style="height:100%;width:100%;" scroll-y="true" bindscroll="scrollFoods" scroll-top="{{scrollTop}}"> <view wx:for="{{goods}}" wx:for-item="item" class="food-list-hook"> <view class="cate">{{item.name}}</view> <view class="food-item" wx:for="{{item.foods}}" wx:for-item="itemFoods"> <view class="icon" ><image src='{{base_url}}{{itemFoods.image}}' mode='aspectFill' /> </view> <view class="content"> <view class="title">{{itemFoods.name}}</view> <view class="desc">{{itemFoods.info}}</view> </view> </view> </view> </scroll-view> /** * 跳到某一个菜单元素 */ scrollToMenu: function (e) { var that = this; let current = e.currentTarget.dataset.current; let toViewString = 'menu-' +current; console.log(current+"和"+toViewString); that.setData({ currentIndex: current, toView: toViewString, scrollTop: that.data.foodListHeights[current] }); }, /** * 监听商品滚动事件 */ scrollFoods: function (e) { var that = this; let currentY = e.detail.scrollTop; console.log(that.data.foodListHeights); for (let i = 0; i < that.data.foodListHeights.length - 1; i++) { let heightBottom = that.data.foodListHeights[i]; let heightTop = that.data.foodListHeights[i + 1]; //对滑动后currentY值不足的情况进行修正 let diff = Math.abs(currentY - heightTop); //判断currentY当前所在的区间 console.log(currentY+"和heightTop:"+heightTop+"和heightBottom:"+heightBottom); if (currentY < heightTop && currentY >= heightBottom) { let toViewString = 'menu-' + (i > 5 ? i - 5 : 0); that.setData({ currentIndex: i, toView: toViewString }); } } },[图片] 当点击左侧菜单时。。执行 scrollToMenu。。。可是居然有时出触发到 scrollFoods这个方法。。。