小程序 scroll-view 的 bindscroll响应不及时,有卡顿
发布于 5 年前 作者 bwei 11714 次浏览 来自 问答

滑动的时候,会出现卡顿现象,触发的bindscroll 函数会卡顿,应该怎么解决

7 回复

卡顿是如何评估的?

也遇到了 相同问题 求解答

我也遇到了,特别在android上

在手机上,touchend后还有一段惯性滚动,这个也会触发bindscroll,请确认代码逻辑有没有考虑这点。

另外,只是单纯的保存scrollTop的状态,不建议setData,直接this._scrollTop = e.detail.scrollTop即可,只有更新界面才应该用setData

嗯嗯,滚动惯性确实没有考虑的,可能是这个原因吧,在iphone6上面就是会先向上滚一下在滑到指定的view,有什么属性可以去除这个惯性吗。还有变量存值哪里,多谢指教。

惯性滚动无法去掉

在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’

                })

            }

        }

    },

回到顶部