滑动的时候,会出现卡顿现象,触发的bindscroll 函数会卡顿,应该怎么解决
在手机上,touchend后还有一段惯性滚动,这个也会触发bindscroll,请确认代码逻辑有没有考虑这点。
另外,只是单纯的保存scrollTop的状态,不建议setData,直接this._scrollTop = e.detail.scrollTop即可,只有更新界面才应该用setData
在scroll上面绑定了bindscroll和bindtouchend,bindscroll用来保存当前视图距离顶部位置,bindtouchend通过获取bindscroll获取的scrollTop的值判断滑动到某个view;但是在开发者滑的时候没问题,在真机上面停止触碰滑动后,会停留个0.5秒左右的时间在滑到指定的view上面。可能是bindtouchend有问题吧。
<scroll-view scroll-y style=“height: {{scrollHeight}}px;” lower-threshold=“150” wx:if="{{index == 0}}" bindscrolltolower=“loadMore” bindscroll=“bindScroll” scroll-into-view="{{recomment_view_id}}" scroll-with-animation="{{true}}" bindtouchend=“bindScrollEnd”>
bindScroll: function(e){
var that = this;
var scrollTop = e.detail.scrollTop;
var activeIndex = that.data.activeIndex;
if(activeIndex == 0){
that.setData({
recomment_scroll_top: scrollTop
})
}else{
that.setData({
new_scroll_top: scrollTop
})
}
},
bindScrollEnd: function(e){
var that = this;
var activeIndex = that.data.activeIndex;
if(activeIndex == 0){
var scrollTop = that.data.recomment_scroll_top;
console.log(scrollTop);
if(scrollTop <= 0){
that.setData({
recomment_view_id: ‘recomment_refresh’
})
that.getShaiList(1);
}
if(scrollTop < 60 && scrollTop > 0){
that.setData({
recomment_view_id: ‘recomment_content’
})
}
}else{
var scrollTop = that.data.new_scroll_top;
if(scrollTop <= 0){
that.setData({
new_view_id: ‘new_refresh’
})
that.getShaiList(1);
}
if(scrollTop < 60 && scrollTop > 0){
that.setData({
new_view_id: ‘new_content’
})
}
}
},