How to prevent document scrolling but allow scrolling inside div elements on websites for iOS and Android?

后端 未结 11 1533
南笙
南笙 2020-12-04 10:43

I created a website with jQueryMobile for iOS and Android.

I don\'t want the document itself to scroll. Instead, just an area (a

element) sh
11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 11:27

    Here is a solution I am using:

    $scrollElement is the scroll element, $scrollMask is a div with style position: fixed; top: 0; bottom: 0;. The z-index of $scrollMask is smaller than $scrollElement.

    $scrollElement.on('touchmove touchstart', function (e) {
        e.stopPropagation();
    });
    
    $scrollMask.on('touchmove', function(e) {
        e.stopPropagation();
        e.preventDefault();
    });
    

提交回复
热议问题