scroll-view在设置了scroll-y以及scroll-into-view之后,每次数据增加就自动滚动到最后一个item,item设置bindlongpress,自动滚动停止以后,长按item无法触发监听事件;当手动滚动scroll-view内部之后,长按item可以触发监听事件,demo代码:
<scroll-view class=“scroll_view” scroll-into-view="{{scrollIntoView}}" scroll-y>
<view
wx:for="{{scrollList}}"
wx:key="{{item.id}}"
bindlongpress=“longpress”
id=“item_{{item.id}}”
class=“item”
>
{{item.cnt}}
</view>
</scroll-view>
Page({
data: {
scrollList: [],
scrollIntoView: ‘’
},
onReady() {
this.startTestScroll();
},
startTestScroll() {
const that = this;
const { scrollList } = this.data;
const time = new Date().getTime();
const item = {
id: time,
cnt: time
};
scrollList.push(item);
that.setData({
scrollList,
scrollIntoView: ‘item_’ + item.id
});
if (scrollList.length < 10) {
setTimeout(() => {
that.startTestScroll();
}, 600);
}
},
longpress() {
wx.showToast({
title: ‘长按成功!’
});
}
})