iOS Safari – How to disable overscroll but allow scrollable divs to scroll normally?

后端 未结 14 1613
南方客
南方客 2020-11-28 17:50

I\'m working on an iPad-based web app, and need to prevent overscrolling so that it seems less like a web page. I\'m currently using this to freeze the viewport and disable

14条回答
  •  旧时难觅i
    2020-11-28 18:19

    Check if the scrollable element is already scrolled to the top when trying to scroll up or to the bottom when trying to scroll down and then preventing the default action to stop the entire page from moving.

    var touchStartEvent;
    $('.scrollable').on({
        touchstart: function(e) {
            touchStartEvent = e;
        },
        touchmove: function(e) {
            if ((e.originalEvent.pageY > touchStartEvent.originalEvent.pageY && this.scrollTop == 0) ||
                (e.originalEvent.pageY < touchStartEvent.originalEvent.pageY && this.scrollTop + this.offsetHeight >= this.scrollHeight))
                e.preventDefault();
        }
    });
    

提交回复
热议问题