收藏
回答

微信小程序scroll-top事件和bindscroll事件冲突

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug scroll-view 工具 6.5.3(所有版本) 2.7.0
<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

这个方法。。。

回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容