Mobile safari position:fixed z-index glitch when scrolling

后端 未结 4 764
礼貌的吻别
礼貌的吻别 2020-12-13 00:22

I know iPhones used to not support position:fixed, but now it does and I\'m seeing a weird glitch when I scroll a fixed position element behind other elements with

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 00:53

    I tried the solution accepted as an answer in a specific case when I needed to set different position in the stack of different layers, but that alone didn't work both in desktop browsers (firefox and chrome) and Safari iOS

    I came out with this hack which uses both translateZ and z-index for each div, which is working in those platforms. The order of translateZ and z-index is important. For setting each layers position is

    -webkit-transform:translateZ(1px);
    -moz-transform:translateZ(1px);
    -o-transform:translateZ(1px);
    transform:translateZ(1px);
    position: relative; 
    z-index: 1; 
    

    I used the same value for the z-index and translateZ just for consistency, it is not necessary. See working example http://jsbin.com/peyehufo/5

提交回复
热议问题