Safari滚动慢,横向选项卡滚动缓慢

1. 解决方法

在需要滚动的元素下添加-webkit-overflow-scrolling: touch;
举个栗子(直接粘贴可用):

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>隐藏横向滚动条</title>
    <style>
    * {
        margin: 0;
        padding: 0;
    }

    .cover {
        width: 100%;
        overflow: hidden;
    }

    .father {
        width: 100%;
        padding: 0 10px;
        background-color: #ff630c;
        overflow-x: auto;
        margin-top: -30px;
        padding-bottom: 30px;
        -webkit-transform: translateY(30px);
        transform: translateY(30px);
        box-sizing: border-box;
    }

    .son {
        width: 500%;
        padding-bottom: 10px;
    }

    .show {
        width: 19%;
        height: 60px;
        background-color: #f00;
        float: left;
        margin-right: 5px;
        text-align: center;
    }

    .second {
        width: 100%;
        height: 50px;
        background-color: #eee;
        z-index: 100000;
    }
    </style>
    <style>
    .father2 {
        overflow-x: scroll;
        width: 100%;
        position: relative;
        top: 10px;
        margin-top: -10px;
        -webkit-overflow-scrolling: touch;
    }

    .son2 {
        width: 500%;
        padding-bottom: 10px;
    }

    .show2 {
        display: inline-block;
        vertical-align: middle;
        letter-spacing: -99999px;
        text-align: center;
        width: 19%;
        margin-right: 10px;
        height: 50px;
        background-color: #f00;
    }
    </style>
</head>

<body>
    <div class="cover">
        <div class="father">
            <div class="son">
                <div class="show">1</div>
                <div class="show">2</div>
                <div class="show">3</div>
                <div class="show">4</div>
                <div class="show">5</div>
            </div>
        </div>
    </div>
    <div class="cover">
        <div class="father2">
            <div class="son2">
                <div class="show2">1</div>
                <div class="show2">2</div>
                <div class="show2">3</div>
                <div class="show2">4</div>
                <div class="show2">5</div>
            </div>
        </div>
    </div>
    <div class="second"></div>
</body>

</html>

二、原因

横向滚动慢,是因为Safari原生支持-webkit-属性,但是默认使用的是浏览器中的渲染行为,所以滑动的时候回卡顿。但是使用这个overflow-scrolling属性以后,会创建一个原生的滚动选项卡,native-scrolling控件,因为滑动的程度会很流畅~~~~至于什么原因,可能就需要熟悉IOS的同学探究一下原生控件咯.
兼容性: IOS5.0 or later.

三、参考网站

https://developer.mozilla.org/zh-CN/docs/Web/CSS/-webkit-overflow-scrolling
https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariCSSRef/Articles/StandardCSSProperties.html#//apple_ref/doc/uid/TP30001266-UserInterface,查找overflow-scrolling就能找到了。

展开阅读全文

没有更多推荐了,返回首页