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

后端 未结 11 1497
南笙
南笙 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:30

    Finally, I got it to work. Really simple:

    var $layer = $("#layer");
    $layer.bind('touchstart', function (ev) {
        var $this = $(this);
        var layer = $layer.get(0);
    
        if ($this.scrollTop() === 0) $this.scrollTop(1);
        var scrollTop = layer.scrollTop;
        var scrollHeight = layer.scrollHeight;
        var offsetHeight = layer.offsetHeight;
        var contentHeight = scrollHeight - offsetHeight;
        if (contentHeight == scrollTop) $this.scrollTop(scrollTop-1);
    });
    

提交回复
热议问题