iOS not respecting z-index with -webkit-overflow-scrolling

后端 未结 4 524
被撕碎了的回忆
被撕碎了的回忆 2021-01-03 20:35

Problem:

On iOS the z-index of a scrollable area is ignored when using -webkit-overflow-scrolling. If two objects with -webkit-over

相关标签:
4条回答
  • 2021-01-03 20:45

    Remove this property dynamically when have need. It's less complicated and do not cause side effects.

    0 讨论(0)
  • 2021-01-03 20:54

    Assuming you face the problem like them. Please, take a look at these post:

    • https://stackoverflow.com/a/20898012/4168867

    • [Solved] Safari for iOS: z-index order bug scrolling a page with a fixed element

    • https://stackoverflow.com/a/9227478/4168867

    Hope this help!

    0 讨论(0)
  • 2021-01-03 21:02

    A really easy fix for this would be to toggle a class to the body on scrolling and target your scrollable windows. If you're scrolling .scrollA then toggle class scrollB to body and apply something like this Javascript/css or you could do it all with javascript, your choice.

    Javascript

    $('#targetDivA').on('scroll touch', function(){
       $('body').toggleClass('scrollB);
    
       //or use this to navigate to it
       //$(this).siblings().toggleClass(\'scrollB\')
    })
    

    CSS

    body.scrollB .targetDivB {
        pointer-events: none;
        /*this eliminates the device from using any event until removed*/
    }
    

    Hope this helps you mate!

    0 讨论(0)
  • 2021-01-03 21:05

    Essentially, what you're experiencing is an iOS bug with -webkit-overflow-scrolling: touch;. In order to solve this bug, as per this answer, just add the following CSS styles to the scrollable div:

    -webkit-transform: translateZ(0px);
    -webkit-transform: translate3d(0,0,0);
    -webkit-perspective: 1000;
    

    So all in all, if you add the above styles to the styles for the scrollable class in your CSS, it should work. Tested on an iPhone 5s running iOS 9. Note that if you scroll down to the bottom or top of the scrollable section that is above everything else, it will start to scroll the body.

    I believe that what those extra styles do is trick the iPhone into using the GPU, but remember that they're only necessary due to a bug with Safari - it's not your fault and these extra styles shouldn't really need to be included. But pop them into your CSS and it should work like a dream!

    0 讨论(0)
提交回复
热议问题