-webkit-overflow-scrolling: touch; breaks in Apple's iOS8

前端 未结 10 1372
刺人心
刺人心 2020-11-30 20:19

I\'m working on a web app that uses -webkit-overflow-scrolling:touch in several places to give the overflown divs inertia scrolling.

Since updating to I

相关标签:
10条回答
  • 2020-11-30 20:41

    I had the same problem in a Cordova web app. For me, the problem was that I had a parent <div> that was animated and had the property animation-fill-mode: forwards;

    Removing this property solved the problem and fixed the broken overflow-scrolling.

    0 讨论(0)
  • 2020-11-30 20:46

    Preventing touch events from surrounding elements bubbling up the DOM is another potential solution, you may notice that scrolling stops when surrounding DIV elements receive the touch or drag events. We had this particular issue in a menu that needed to scroll smoothly. Turning off those events helped stop the "sticking" of the scroll able element.

    $html.bind('touchmove', scrollLock );
    
    var scrollLock = function(e) {
            if( $body.hasClass('menu-open') ){
                    e.stopPropagation();
                    e.preventDefault();
            }
    };
    
    $html.unbind('touchmove', scrollLock );
    
    0 讨论(0)
  • 2020-11-30 20:48

    I've been having some trouble with it too but in a slightly different scenario.

    I do have my divs with inertia without any problems.

    I have a simple JSFiddle where you can have a look.

    https://jsfiddle.net/SergioM/57f2da87/17/

    .scrollable {
        width:100%;
        height:200px;
        -webkit-overflow-scrolling:touch;
        overflow:scroll;
    }
    

    Hope it helps.

    0 讨论(0)
  • 2020-11-30 20:50

    I had this problem while using the angular bootstrap modal. I fixed it by creating my own stylesheet and removing the fixed width and margin in the media queries.

    ORIGINAL:

      .modal-dialog {
        position: relative;
        width: auto;
        margin: 10px;
      }
    
    @media (min-width: 768px) {
      .modal-dialog {
          width: 600px;
          margin: 30px auto;
      }
        .modal-content {
            -webkit-box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
        }
        .modal-sm {
            width: 300px;
        }
    }
    @media (min-width: 992px) {
        .modal-lg {
            width: 900px;
        }
    }
    

    CHANGES:

    .modal-dialog {
        margin: 0px;
        margin-top: 30px;
        margin-left: 5%;
        margin-right: 5%;
    }
    
    @media (min-width: 768px) {
        .modal-dialog {
            width: auto;
            margin-left: 10%;
            margin-right: 10%;
        }
        .modal-content {
           -webkit-box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
           box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
        }
    }
    
    @media (min-width: 992px) {
        .modal-dialog {
            width: auto;
            margin-left: 15%;
            margin-right: 15%;
        }  
    }
    
    0 讨论(0)
  • 2020-11-30 20:52

    I tried every solutions here without success. I was able to make it work by having the property -webkit-overflow-scrolling: touch; on the scrollable div AND on the parent container.

    div.container {
        -webkit-overflow-scrolling: touch;
    }
    
    div.container > div.scrollable {
        -webkit-overflow-scrolling: touch;
        overflow-y: auto;
    }
    
    0 讨论(0)
  • 2020-11-30 20:55

    I had a similar problem with a (quite complex) nested scrollable div which scrolled fine in iOS 5, 6 and 7, but that intermittently failed to scroll in iOS 8.1.

    The solution I found was to remove all the CSS that tricks the browser into using the GPU:

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

    By doing this, the '-webkit-overflow-scrolling: touch;' can still be included and still function as normal.

    It did mean sacrificing the (for me, dubious) gains to scrolling performance that the above hacks gave in earlier incarnations of iOS, but in the choice between that and inertia scrolling, the inertia scrolling was deemed more important (and we don't support iOS 5 anymore).

    I cannot at this stage say why this conflict exists; it may be that it is a bad implementation of these features, but I suspect there is something a bit deeper in the CSS that is causing it. I am currently trying to create a pared down HTML/CSS/JS configuration to demonstrate it, but maybe the heavy markup structure and the large amounts of dynamic data is necessary for it to happen.

    Addendum: I did, however, have to point out to our client that if even with this fix the user starts trying to scroll on a non-scrollable element she will have to wait a second after stopping before being able to scroll the scrollable element. This is native behaviour.

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