Disabling android's chrome pull-down-to-refresh feature

前端 未结 15 2548
予麋鹿
予麋鹿 2020-12-02 04:20

I\'ve created a small HTML5 web application for my company.

This application displays a list of items and everything works fine.

The application is mainly us

15条回答
  •  [愿得一人]
    2020-12-02 04:40

    Pure js solution.

    // Prevent pull refresh chrome
        var lastTouchY = 0;
        var preventPullToRefresh = false;
        window.document.body.addEventListener("touchstart", function(e){
            if (e.touches.length != 1) { return; }
            lastTouchY = e.touches[0].clientY;
            preventPullToRefresh = window.pageYOffset == 0;
        }, false);
    
        window.document.body.addEventListener("touchmove", function(e){
    
            var touchY = e.touches[0].clientY;
            var touchYDelta = touchY - lastTouchY;
            lastTouchY = touchY;
            if (preventPullToRefresh) {
                // To suppress pull-to-refresh it is sufficient to preventDefault the first overscrolling touchmove.
                preventPullToRefresh = false;
                if (touchYDelta > 0) {
                    e.preventDefault();
                    return;
                }
            }
    
        }, false);
    

提交回复
热议问题