简体   繁体   中英

CSS / JS transform:translate3d and scrolling - smooth on Android, no momentum on iPhone

I currently have a mobile website project in which I'm creating panels such that one panel can be viewed at a time, where when a user swipes left or right, the panel slides offscreen and a new panel slides in. Everything works fine on Android, and even behavior is acceptable on iPhone.

However, scrolling on iPhone seems to lack momentum. In other words, when "flicking" the panel up / down, it scrolls on Android natively, but on iPhone it seems to lose momentum very quickly. I'd like to find a simple CSS or combo CSS / JS solution that works, without including additional libraries if possible.

Here's the basic structure of the site:

<html>
    <head>Head stuff here</head>
    <body>
        <div class="container">
            <div class="headbox">Fixed position menu here</div>
            <div id="pages">
                <div class="page">Page panel here</div>
                <div class="page">Page panel here</div>
                <div class="page">Page panel here</div>
            </div>
            <div class="bottommenu">Fixed position bottom menu here</div>
        </div>
    </body>
</html>

Here is the basic CSS:

body {
    width:100%;
    overflow-x:hidden;
    font-size:17px;
    border-collapse:collapse;
}
.container {
    width:100%;
    height:100%;
    overflow-x:hidden;
overflow-y:scroll;
    position:relative;
    /*-webkit-perspective:1000;
-webkit-backface-visibility:hidden;*/
}
.headbox {
font-size:17px;
    height:2.3529em;
    width:100%;
    top:0;
    position:fixed;
    text-align:center;
    color:#fff;
    z-index:1;
}
#pages {
    width:100%;
    height:100%;
    white-space:nowrap;
    font-size:0;
    -webkit-backface-visibility:hidden;
-webkit-transform-style:preserve-3d;
    position:relative;
    -webkit-transform:translate3d(-100%,0,0);
    -moz-transform:translate3d(-100%,0,0);
    -ms-transform:translate3d(-100%,0,0);
    -o-transform:translate3d(-100%,0,0);
    transform:translate3d(-100%,0,0);
}
.page {
    width:100%;
    height:100%;
    display:inline-block;
    vertical-align:top;
position:relative;
white-space:normal;
    background:#fff;
font-size:17px;
}
.bottommenu {
    position:fixed;
bottom:0;
    left:0;
    width:100%;
    height:.2em;
    transition:height 400ms;
    -webkit-transition:height 400ms;
    -moz-transition:height 400ms;
    -ms-transition:height 400ms;
    -o-transition:height 400ms;
    z-index:1;
}

And finally, the listener for scrolling, which shouldn't interfere with CSS or the ability to repaint, but maybe I am missing something:

var that = this;
$(document).scroll(function(){
if (!that.direction && !that.loading) {
    that.direction = 'vertical';
    that.moving = true;
    if (that.scrolling) { clearTimeout(that.scrolling); }
    that.scrolling = setTimeout(function() {
    that.direction = false;
    that.sliding = 0;
    that._getMore();
    that.moving = false;
    },500);
}
});

Any ideas? I've tried numerous variations of -webkit-overflow-scrolling:touch; , overflow-y:scroll; , and other possible hacks / fixes / supported syntax, but nothing seems to help. I need the content to scroll within the body tag so that on iPhone the screen resizes itself on scroll, otherwise I'd use a scrollable div. This is not an option.

I guess problem with loss of native elastic scrolling within container with position: relative; overflow: hidden position: relative; overflow: hidden .

Try -webkit-overflow-scrolling: touch; for .container .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM