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

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

    How about this CSS only solution:

    https://jsfiddle.net/Volker_E/jwGBy/24/

    body gets position: fixed; and every other element you wish an overflow: scroll;. Works on mobile Chrome (WebKit)/Firefox 19/Opera 12.

    You'll also see my various attempts towards a jQuery solution. But as soon as you're binding touchmove/touchstart to document, it hinders scrolling in the child div no matter if unbinded or not.

    Disclaimer: Solutions to this problem are in many ways basically not very nice UX-wise! You'll never know how big the viewport of your visitors exactly is or which font-size they are using (client user-agent style like), therefore it could easily be, that important content is hidden to them in your document.

提交回复
热议问题