移动web开发入门-学习笔记-5

移动端常见问题

一、浏览器兼容性

htm5l兼容 | css3兼容 | js兼容

<style>
        header, footer {
            width: 100%;
            height: 50px;
        }
        header {
            background-color: red;

            /*display: -webkit-flex;
            display: -moz-flex;
            display: -ms-flex;
            display: -o-flex;
            display: flex;
            justify-content: center;
            -ms-align-items: center;
            align-items: center;*/
            /*text-align: center;
            line-height: 50px;*/
        }
        footer {
            background-color: green;
        }

        .flexbox header {
            display: -webkit-flex;
            display: -moz-flex;
            display: -ms-flex;
            display: -o-flex;
            display: flex;
            justify-content: center;
            -ms-align-items: center;
            align-items: center;
        }
        .no-flexbox header {
            text-align: center;
            line-height: 50px;
        }
    </style>
    <script src="js/html5shiv.min.js"></script>
    <script src="js/modernizr.js"></script>
</head>
<body>
    <header>header</header>
    <footer>footer</footer>

    <script>
        // if (requestAnimationFrame) { // 错误
        //     // ...
        // }
        // if (window.requestAnimationFrame) { // 正确

        // } else {

        // }

        var requestAnimationFrame = window.requestAnimationFrame ||
            window.webkitRequestAnimationFrame ||
            window.mozRequestAnimationFrame ||
            window.oRequestAnimationFrame ||
            window.msRequestAnimationFrame ||
            function (fn) {
                setTimeout(fn, 16);
            };

            requestAnimationFrame(function () {
                console.log(1);
            });
    </script>
</body>

二、移动端动画

在这里插入图片描述

三、click 300ms 延迟

根本原因:double click 双击

移动端默认双击情况下会有方法效果,当你点击一次之后,移动端无法判断你是否下一次还会继续完成双击,因此存在300 ms 延迟

有一部分浏览器,比如chrome浏览器,当你在meta头设置width=device-width时,它会自动禁止300 ms的延迟

推荐的解决方法:fastclick https://github.com/ftlabs/fastclick

原理:当检测到touchend事件后,会触发自己模拟的click事件

四、单行和多行文字溢出省略

 <style>
        /*css reset*/
        * {
            padding: 0;
            margin: 0;
        }
        body {
            font-size: 12px;
            color: #5d655b;
        }
        a {
            font-size: 12px;
            color: #686868;
            text-decoration: none;
            -webkit-tap-highlight-color: transparent;
        }
        img {
            vertical-align: top;
            border: none;
            width: 100%;
        }

        /*recommend*/
        .recommend-item {
            width: 50%;
            background-color: #fff;
            box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.12);
            margin: 20px auto;
        }
        .recommend-link {
            display: block;
            width: 100%;
            height: 100%;
        }
        .recommend-pic {
            width: 100%;
            margin-bottom: 8px;
        }
        .recommend-img {
            width: 100%;
            height: 100%;
        }
        .recommend-name,
        .recommend-origPrice,
        .recommend-info {
            padding: 0 10px;
            margin-bottom: 8px;
        }
        .recommend-origPrice {
            color: #ccc;
        }
        .recommend-info {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .recommend-price {
            color: #e61414;
        }
        .recommend-price-num {
            font-size: 20px;
        }
        .recommend-count {
            color: #999;
        }

        .recommend-name {
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .text-ellipsis {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .multiline-ellipsis {
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
            white-space: normal !important;
            word-wrap: break-word;
        }
        .recommend-name {
            /*height: 30px;*/
            /*height: 100px;*/
        }
    </style>
</head>
<body>
    <div class="recommend-item">
        <a href="###" class="recommend-link">
            <p class="recommend-pic">
                <img src="img/1.jpg" alt="recommend" class="recommend-img">
            </p>
            <!-- <p class="recommend-name"><span class="text-ellipsis">欧派整体橱柜定制简约现代 欧派整体橱柜定制简约现代欧派整体橱柜定制简约现代欧派整体橱柜定制简约现代</span></p> -->
            <p class="recommend-name multiline-ellipsis">欧派整体橱柜定制简约现代 欧派整体橱柜定制简约现代欧派整体橱柜定制简约现代欧派整体橱柜定制简约现代</p>
            <p class="recommend-origPrice">
                <del>¥2000.00</del>
            </p>
            <p class="recommend-info">
                <span class="recommend-price">¥<strong class="recommend-price-num">1000</strong></span>
                <span class="recommend-count">985件已售</span>
            </p>
        </a>
    </div>
</body>

五、水平居中和垂直居中

<title>2.5 水平居中和垂直居中</title>
    <style>
        * {
            box-sizing: border-box;
            padding: 0;
            margin: 0;
        }
        .modal-wrapper {
            position: fixed;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            z-index: 1000;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.4);

            /*display: flex;
            justify-content: center;
            align-items: center;*/
        }
        .modal {
            overflow: hidden;
            background-color: #fff;
            border-radius: 10px;
            font-size: 16px;

            /*1 容器宽高自适应 没有指定宽高 内容撑开*/
                /*1-1 内联元素 不能设置宽高 内容撑开*/
                    /*1-1-1 文字水平垂直居中 多行文字*/
                    /*display: inline;*/
                    /*padding: 30px 20px;*/
                    /*padding: 0 20px;*/

                    /*1-1-2 容器水平垂直居中 内联元素*/
                    /*position: absolute;
                    left: 50%;
                    top: 50%;
                    transform: translate(-50%, -50%);*/
                    

                /*1-2 内联块元素 不能设置宽高 内容撑开*/
                    /*1-2-1 文字水平垂直居中 多行文字*/
                    /*display: inline-block;
                    padding: 30px 20px;*/

                    /*1-2-2 容器水平垂直居中 内联块元素*/
                    /*position: absolute;
                    left: 50%;
                    top: 50%;
                    transform: translate(-50%, -50%);*/
                
                /*1-3 块元素 不能设置宽高*/
                    /*1-3-1 文字水平垂直居中 多行文字*/
                    /*display: block;
                    text-align: center;
                    padding: 30px 0;*/

                    /*1-3-2 容器水平垂直居中 块元素*/
                    /*position: absolute;
                    left: 50%;
                    top: 50%;
                    transform: translate(-50%, -50%);*/
                    
            
            /*2 指定容器宽高宽高*/
                /*2-1 内联元素 不能设置宽高 内容撑开*/

                /*2-2 内联块元素 设置宽高*/
                    /*2-2-1 文字水平垂直居中 多行文字*/
                    /*display: inline-block;
                    width: 300px;
                    height: 100px;
                    text-align: center;
                    line-height: 100px;*/

                    /*多行文字*/
                    /*display: flex;
                    justify-content: center;
                    align-items: center;*/

                    /*2-2-2 容器水平垂直居中 内联块元素*/
                    /*position: absolute;
                    left: 50%;
                    top: 50%;
                    transform: translate(-50%, -50%);*/
                    /*margin-left: -150px;
                    margin-top: -50px;*/
                    
                
                /*2-3 块元素 设置宽高*/
                    /*2-3-1 文字水平垂直居中 多行文字*/
                    display: block;
                    width: 300px;
                    height: 100px;
                    text-align: center;
                    line-height: 100px;
                    
                    /*2-3-2 容器水平垂直居中 块元素*/
                    /*margin: 0 auto;*/
                    position: absolute;
                    left: 50%;
                    top: 50%;
                    /*transform: translate(-50%, -50%);*/
                    margin-left: -150px;
                    margin-top: -50px;
        }
    </style>
</head>
<body>
    <div class="modal-wrapper">
        <span class="modal">单行文字水平垂直居中</span>
        <!-- <span class="modal">多行文字水平垂直居中 多行文字水平垂直居中多行文字水平垂直居中</span> -->
    </div>
</body>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值