<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
这个方法。。。
麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)
https://developers.weixin.qq.com/s/JhCnvwml7a8l
点击左边的时候,相当于也是改变了scroll的值,会触发
那为什么触发的值不一样。。。会有误差。。
scroll值误差?截图看下?
就我点击左边 设置scroll-top 值。。然后到触发
scrollFoods
滚动事件 时 获取的scroll-top 值 存在误差。。。