position: fixed doesn't work on iPad and iPhone

后端 未结 15 2084
一整个雨季
一整个雨季 2020-11-22 16:16

I have been struggling with fixed positioning in iPad for a while. I know iScroll and it does not always seem to work (even in their demo). I also know that Sencha has a fix

15条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 16:39

    This might not be applicable to all scenarios, but I found that the position: sticky (same thing with position: fixed) only works on old iPhones when the scrolling container is not the body, but inside something else.

    Example pseudo html:

    body                         <- scrollbar
       relative div
           sticky div
    

    The sticky div will be sticky on desktop browsers, but with certain devices, tested with: Chromium: dev tools: device emultation: iPhone 6/7/8, and with Android 4 Firefox, it will not.

    What will work, however, is

    body
        div overflow=auto       <- scrollbar
            relative div
                sticky div
    

提交回复
热议问题