移动端实现表头固定,tbody滚动的三种方法

更新日期: 2019-05-30阅读: 2.5k标签: 移动端

实现表头固定,tbody垂直滚动。准备工作:获取页面可是区域高度

function setIframeHeight() {
    var screenHeight = document.documentElement.clientHeight;
}

2.屏幕旋转触发事件

window.addEventListener("resize",()=>{
    //正常方向或者屏幕旋转180°
    if(window.orientation===180||window.orientation===0){
        console.log('竖屏');
    }
    //屏幕顺时针旋转90°或者逆时针旋转90°
    if (window.orientation===90||window.orientation===-90) {
        console.log('横屏');
    }
})


方法一:两个table

思路:第一个table放表头,第二个table方内容。循环获取tbody第一行单元格的宽度,给thead的单元格,使表头对齐

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

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>两个table</title>
    <link rel="stylesheet" href="css/css.css">
    <script src="js/jquery.min.js"></script>
    <style>
        .scrollX{overflow-x: scroll}
        tr th,td {
            border: 1px solid #000;
            padding: 8px;
            white-space: nowrap;
        }
        .table-head {
            padding-right: 17px;
            background-color: #eeeeee;
            color: #000;
        }

        .table-body {
            display: block;
            height: 300px;
            overflow-y: scroll;
        }
        .table-head table,
        .table-body table {
            border-collapse: collapse;
            width: 100%;
        }

        .table-body table tr:nth-child(2n+1) {
            background-color: #f2f2f2;
        }
    </style>
</head>

<body>
    <div class="scrollX">
        <table class="table-head">
            <thead>
                <tr>
                    <th>部门</th>
                    <th>用户名称</th>
                    <th>1月</th>
                    <th>2月</th>
                    <th>3月</th>
                    <th>4月</th>
                    <th>5月</th>
                    <th>6月</th>
                    <th>7月</th>
                    <th>8月</th>
                    <th>9月</th>
                    <th>10月</th>
                    <th>11月</th>
                    <th>12月</th>
                    <th>合计</th>
                </tr>
            </thead>
        </table>
        <table class="table-body">
            <tbody>
                <tr>
                    <td>这是一个表格内容</td>
                    <td>这是一个表格内容</td>
                    <td>这是一个表格内容</td>
                    <td>这是一个表格内容</td>
                    <td>这是一个表格内容</td>
                    <td>这是一个表格内容</td>
                    <td>这是一个表格内容</td>
                    <td>这是一个表格内容</td>
                    <td>这是一个表格内容</td>
                    <td>这是一个表格内容</td>
                    <td>这是一个表格内容</td>
                    <td>这是一个表格内容</td>
                    <td>这是一个表格内容</td>
                    <td>这是一个表格内容</td>
                    <td>这是一个表格内容</td>
                </tr>
               <!-- 循环多次tr...-->
            </tbody>
        </table>
    </div>
        <script>

            //内容第一行
            var bodyTR = $(".table-body tr:eq(1) td");
            // 一行有多少个单元格
            var bodyTRLength = bodyTR.length;
            //宽度
            var autoW = $('.table-body tbody').width()
            var headTR = $(".table-head tr th")
            //获取表头高度
            var headH=$(".table-head").height();
            function setIframeHeight() {
                var screenHeight = document.documentElement.clientHeight-headH;
                $(".table-body").height(screenHeight);
            }
            //屏幕发生旋转重新计算高度
            window.addEventListener("resize",()=>{
                if(window.orientation===180||window.orientation===0){
                    setIframeHeight();
                }if (window.orientation===90||window.orientation===-90) {
                    setIframeHeight();
                }
            })
            $(function () {
                setIframeHeight();
                $(".table-head").css("width",autoW+1);
                $(".table-body").css("width",autoW+18);
                for (var i = 1; i < bodyTRLength; i++) {
                    var tdW = $(".table-body tr:eq(1) td:eq("+i+")").width()+1;
                    $(".table-head tr th:eq(" + (i ) + ")").css("width", tdW)
                }
            })

        </script>
    </table>
</body>
</html>


第二种方法:通过JS实现

思路:监听滚动事件,动态控制表头位置

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>JS 实现表头tbody固定滚动</title>
    <script src="js/jquery.min.js"></script>
    <link rel="stylesheet" href="css/css.css" />
    <style>
      .table tr th,td {
        border: 1px solid #000;
      }
      .table-responsive {
        overflow-y: scroll;
      }
      .text-center td {
        white-space: nowrap;
        padding: 10px;
      }
      .table-th-css {
        background: #efeff4 !important;
        position: relative !important;
        text-align: center;
        top: 0;
        white-space: nowrap;
      }
      .table-th-css div {
        border-top: none;
        white-space: nowrap;
        padding: 10px;
      }
      .section-scroll {
        height: 417px;
      }
    </style>
  </head>

  <body>
    <div class="table-responsive section-scroll">
      <table class="table table-bordered">
        <thead class="table-header">
          <tr>
            <th class="table-th-css">
              <div>部门</div>
            </th>
            <th class="table-th-css">
              <div>用户名称</div>
            </th>
            <th class="text-center table-th-css">
              <div>1月</div>
            </th>
            <th class="text-center table-th-css">
              <div>2月</div>
            </th>
            <th class="text-center table-th-css">
              <div>3月</div>
            </th>
            <th class="text-center table-th-css">
              <div>4月</div>
            </th>
            <th class="text-center table-th-css">
              <div>5月</div>
            </th>
            <th class="text-center table-th-css">
              <div>6月</div>
            </th>
            <th class="text-center table-th-css">
              <div>7月</div>
            </th>
            <th class="text-center table-th-css">
              <div>8月</div>
            </th>
            <th class="text-center table-th-css">
              <div>9月</div>
            </th>
            <th class="text-center table-th-css">
              <div>10月</div>
            </th>
            <th class="text-center table-th-css">
              <div>11月</div>
            </th>
            <th class="text-center table-th-css">
              <div>12月</div>
            </th>
            <th class="text-center table-th-css">
              <div>合计</div>
            </th>
          </tr>
        </thead>
        <tbody>
          <tr class="text-center">
            <td>这是一个表格内容</td>
            <td class="table-textWidth">这是一个表格内容</td>
            <td>这是一个表格内容</td>
            <td>这是一个表格内容</td>
            <td>这是一个表格内容</td>
            <td>这是一个表格内容</td>
            <td>这是一个表格内容</td>
            <td>这是一个表格内容</td>
            <td>这是一个表格内容</td>
            <td>这是一个表格内容</td>
            <td>这是一个表格内容</td>
            <td>这是一个表格内容</td>
            <td>这是一个表格内容</td>
            <td>这是一个表格内容</td>
            <td>这是一个表格内容</td>
          </tr>
          <!-- 循环多次tr...-->
        </tbody>
      </table>
    </div>
    <script>
      $(function() {
        setIframeHeight();
      });
      //屏幕发生旋转重新计算高度
      window.addEventListener("resize",()=>{
          if(window.orientation===180||window.orientation===0){
            setIframeHeight();
          }if (window.orientation===90||window.orientation===-90) {
            setIframeHeight();
          }
      })
      var tableCont = $(".section-scroll tr th");
      //获取th
      var tableCont_child = $(".section-scroll tr th div");
      //获取th下边的div
      var tableScroll = $(".section-scroll");
      //获取滚动条同级的class
      function scrollHandle() {
        console.log(1)
        var scrollTop = tableScroll.scrollTop();
        // 当滚动距离大于0时设置top及相应的样式
        if (scrollTop > 0) {
          tableCont.css({"top": scrollTop + "px", "padding":"0"
          });
          tableCont_child.css({"borderTop": "1px solid #000","borderBottom": "1px solid #000","marginTop": "-1px","padding": "8px"
          });
        } else {
          // 当滚动距离小于0时设置top及相应的样式
          tableCont.css({ "top": scrollTop + "px", "marginTop": "0" });
          tableCont_child.css({ "border": "none", "marginTop": 0, "marginBottom": 0, })
        }
      }
      tableScroll.on("scroll", scrollHandle);
      //获取可是区域高度
      function setIframeHeight() {
        var screenHeight = document.documentElement.clientHeight;
        $(".section-scroll").height(screenHeight);
      }
    </script>
  </body>
</html>


第三种方法 通过easyui实现

思路,引用easyui文件并实现触加载更多数据,合计行

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">  
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>Basic DataGrid - jQuery EasyUI Mobile Demo</title>  
    <link rel="stylesheet" type="text/css" href="easyui/themes/metro/easyui.css">  
    <link rel="stylesheet" type="text/css" href="easyui/themes/mobile.css">  
    <link rel="stylesheet" type="text/css" href="easyui/themes/icon.css">  
    <script type="text/javascript" src="js/jquery.min.js"></script>  
    <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script> 
    <script type="text/javascript" src="easyui/jquery.easyui.mobile.js"></script> 
    <!-- <script type="text/javascript" src="https://www.jeasyui.com/easyui/datagrid-bufferview.js"></script>
</head> -->
<style>
    body{
        margin: 0;
        padding: 0;
    }
    .datagrid-footer td{
        color: red
    }
</style>
<body>
        <div id="hh">
                <div>
                    <div>Basic DataGrid</div>
                </div>
            </div>
    <table id="dg">  
        <thead>  
            <tr>  
                <th data-options="field:'itemid',width:80">Item ID</th>  
                <th data-options="field:'productid',width:100">Product</th>  
                <th data-options="field:'listprice',width:80,align:'right'">List Price</th>  
                <th data-options="field:'unitcost',width:80,align:'right'">Unit Cost</th>  
                <!-- <th data-options="field:'itemid',width:80">Item ID</th>  
                <th data-options="field:'productid',width:100">Product</th>  
                <th data-options="field:'listprice',width:80,align:'right'">List Price</th>  
                <th data-options="field:'unitcost',width:80,align:'right'">Unit Cost</th>  
                <th data-options="field:'itemid',width:80">Item ID</th>  
                <th data-options="field:'productid',width:100">Product</th>  
                <th data-options="field:'listprice',width:80,align:'right'">List Price</th>  
                <th data-options="field:'unitcost',width:80,align:'right'">Unit Cost</th>  
                <th data-options="field:'itemid',width:80">Item ID</th>  
                <th data-options="field:'productid',width:100">Product</th>  
                <th data-options="field:'listprice',width:80,align:'right'">List Price</th>  
                <th data-options="field:'unitcost',width:80,align:'right'">Unit Cost</th>  
                <th data-options="field:'itemid',width:80">Item ID</th>  
                <th data-options="field:'productid',width:100">Product</th>  
                <th data-options="field:'listprice',width:80,align:'right'">List Price</th>  
                <th data-options="field:'unitcost',width:80,align:'right'">Unit Cost</th>  
                <th data-options="field:'itemid',width:80">Item ID</th>  
                <th data-options="field:'productid',width:100">Product</th>  
                <th data-options="field:'listprice',width:80,align:'right'">List Price</th>  
                <th data-options="field:'unitcost',width:80,align:'right'">Unit Cost</th>   -->
            </tr>
        </thead>  
    </table>
    <script>
        
        var data ={     
            "total":5,
            "rows":[
            {"productid":"FI-SW-01","productname":"Koi","unitcost":10.00,"status":"P","listprice":36.50,"attr1":"Large","itemid":"EST-1"},
            {"productid":"K9-DL-01","productname":"Dalmation","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Spotted Adult Female","itemid":"EST-10"},
            {"productid":"RP-SN-01","productname":"Rattlesnake","unitcost":12.00,"status":"P","listprice":38.50,"attr1":"Venomless","itemid":"EST-11"},
            {"productid":"RP-SN-01","productname":"Rattlesnake","unitcost":12.00,"status":"P","listprice":26.50,"attr1":"Rattleless","itemid":"EST-12"},
            {"productid":"RP-LI-02","productname":"Iguana","unitcost":12.00,"status":"P","listprice":35.50,"attr1":"Green Adult","itemid":"EST-13"},
            {"productid":"FL-DSH-01","productname":"Manx","unitcost":12.00,"status":"P","listprice":158.50,"attr1":"Tailless","itemid":"EST-14"},
            {"productid":"FL-DSH-01","productname":"Manx","unitcost":12.00,"status":"P","listprice":83.50,"attr1":"With tail","itemid":"EST-15"},
            {"productid":"FL-DLH-02","productname":"Persian","unitcost":12.00,"status":"P","listprice":23.50,"attr1":"Adult Female","itemid":"EST-16"},
            {"productid":"FL-DLH-02","productname":"Persian","unitcost":12.00,"status":"P","listprice":89.50,"attr1":"Adult Male","itemid":"EST-17"},
            {"productid":"FI-SW-01","productname":"Koi","unitcost":10.00,"status":"P","listprice":36.50,"attr1":"Large","itemid":"EST-1"},
            {"productid":"K9-DL-01","productname":"Dalmation","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Spotted Adult Female","itemid":"EST-10"},
            {"productid":"RP-SN-01","productname":"Rattlesnake","unitcost":12.00,"status":"P","listprice":38.50,"attr1":"Venomless","itemid":"EST-11"},
            {"productid":"RP-SN-01","productname":"Rattlesnake","unitcost":12.00,"status":"P","listprice":26.50,"attr1":"Rattleless","itemid":"EST-12"},
            {"productid":"RP-LI-02","productname":"Iguana","unitcost":12.00,"status":"P","listprice":35.50,"attr1":"Green Adult","itemid":"EST-13"},
            {"productid":"FL-DSH-01","productname":"Manx","unitcost":12.00,"status":"P","listprice":158.50,"attr1":"Tailless","itemid":"EST-14"},
            {"productid":"FL-DSH-01","productname":"Manx","unitcost":12.00,"status":"P","listprice":83.50,"attr1":"With tail","itemid":"EST-15"},
            {"productid":"FL-DLH-02","productname":"Persian","unitcost":12.00,"status":"P","listprice":23.50,"attr1":"Adult Female","itemid":"EST-16"},
            {"productid":"FL-DLH-02","productname":"Persian","unitcost":12.00,"status":"P","listprice":89.50,"attr1":"Adult Male","itemid":"EST-17"},
            {"productid":"FI-SW-01","productname":"Koi","unitcost":10.00,"status":"P","listprice":36.50,"attr1":"Large","itemid":"EST-1"},
            {"productid":"K9-DL-01","productname":"Dalmation","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Spotted Adult Female","itemid":"EST-10"},
            {"productid":"RP-SN-01","productname":"Rattlesnake","unitcost":12.00,"status":"P","listprice":38.50,"attr1":"Venomless","itemid":"EST-11"},
            {"productid":"RP-SN-01","productname":"Rattlesnake","unitcost":12.00,"status":"P","listprice":26.50,"attr1":"Rattleless","itemid":"EST-12"},
            {"productid":"RP-LI-02","productname":"Iguana","unitcost":12.00,"status":"P","listprice":35.50,"attr1":"Green Adult","itemid":"EST-13"},
            {"productid":"FL-DSH-01","productname":"Manx","unitcost":12.00,"status":"P","listprice":158.50,"attr1":"Tailless","itemid":"EST-14"},
            {"productid":"FL-DSH-01","productname":"Manx","unitcost":12.00,"status":"P","listprice":83.50,"attr1":"With tail","itemid":"EST-15"},
            {"productid":"FL-DLH-02","productname":"Persian","unitcost":12.00,"status":"P","listprice":23.50,"attr1":"Adult Female","itemid":"EST-16"},
            {"productid":"FL-DLH-02","productname":"Persian","unitcost":12.00,"status":"P","listprice":89.50,"attr1":"Adult Male","itemid":"EST-17"},
            {"productid":"AV-CB-01","productname":"Amazon Parrot","unitcost":92.00,"status":"P","listprice":63.50,"attr1":"Adult Male","itemid":"EST-18"}
        ],
            "footer":[{"productid":"合计","unitcost":"1203.00","listprice":"5895.00"}]
        };
        var pushdata =[
            {"productid":"FI-SW-01","productname":"Koi","unitcost":10.00,"status":"P","listprice":36.50,"attr1":"Large","itemid":"EST-1"},
            {"productid":"K9-DL-01","productname":"Dalmation","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Spotted Adult Female","itemid":"EST-10"},
            {"productid":"RP-SN-01","productname":"Rattlesnake","unitcost":12.00,"status":"P","listprice":38.50,"attr1":"Venomless","itemid":"EST-11"},
            {"productid":"RP-SN-01","productname":"Rattlesnake","unitcost":12.00,"status":"P","listprice":26.50,"attr1":"Rattleless","itemid":"EST-12"},
            {"productid":"RP-LI-02","productname":"Iguana","unitcost":12.00,"status":"P","listprice":35.50,"attr1":"Green Adult","itemid":"EST-13"},
            {"productid":"FL-DSH-01","productname":"Manx","unitcost":12.00,"status":"P","listprice":158.50,"attr1":"Tailless","itemid":"EST-14"},
            {"productid":"FL-DSH-01","productname":"Manx","unitcost":12.00,"status":"P","listprice":83.50,"attr1":"With tail","itemid":"EST-15"},
            {"productid":"FL-DLH-02","productname":"Persian","unitcost":12.00,"status":"P","listprice":23.50,"attr1":"Adult Female","itemid":"EST-16"},
            {"productid":"FL-DLH-02","productname":"Persian","unitcost":12.00,"status":"P","listprice":89.50,"attr1":"Adult Male","itemid":"EST-17"},
            {"productid":"FI-SW-01","productname":"Koi","unitcost":10.00,"status":"P","listprice":36.50,"attr1":"Large","itemid":"EST-1"},
            {"productid":"K9-DL-01","productname":"Dalmation","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Spotted Adult Female","itemid":"EST-10"},
            {"productid":"RP-SN-01","productname":"Rattlesnake","unitcost":12.00,"status":"P","listprice":38.50,"attr1":"Venomless","itemid":"EST-11"},
            {"productid":"RP-SN-01","productname":"Rattlesnake","unitcost":12.00,"status":"P","listprice":26.50,"attr1":"Rattleless","itemid":"EST-12"},
            {"productid":"RP-LI-02","productname":"Iguana","unitcost":12.00,"status":"P","listprice":35.50,"attr1":"Green Adult","itemid":"EST-13"},
            {"productid":"FL-DSH-01","productname":"Manx","unitcost":12.00,"status":"P","listprice":158.50,"attr1":"Tailless","itemid":"EST-14"},
            {"productid":"FL-DSH-01","productname":"Manx","unitcost":12.00,"status":"P","listprice":83.50,"attr1":"With tail","itemid":"EST-15"},
            {"productid":"FL-DLH-02","productname":"Persian","unitcost":12.00,"status":"P","listprice":23.50,"attr1":"Adult Female","itemid":"EST-16"},
            {"productid":"FL-DLH-02","productname":"Persian","unitcost":12.00,"status":"P","listprice":89.50,"attr1":"Adult Male","itemid":"EST-17"},
            {"productid":"FI-SW-01","productname":"Koi","unitcost":10.00,"status":"P","listprice":36.50,"attr1":"Large","itemid":"EST-1"},
            {"productid":"K9-DL-01","productname":"Dalmation","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Spotted Adult Female","itemid":"EST-10"},
            {"productid":"RP-SN-01","productname":"Rattlesnake","unitcost":12.00,"status":"P","listprice":38.50,"attr1":"Venomless","itemid":"EST-11"},
            {"productid":"RP-SN-01","productname":"Rattlesnake","unitcost":12.00,"status":"P","listprice":26.50,"attr1":"Rattleless","itemid":"EST-12"},
            {"productid":"RP-LI-02","productname":"Iguana","unitcost":12.00,"status":"P","listprice":35.50,"attr1":"Green Adult","itemid":"EST-13"},
            {"productid":"FL-DSH-01","productname":"Manx","unitcost":12.00,"status":"P","listprice":158.50,"attr1":"Tailless","itemid":"EST-14"},
            {"productid":"FL-DSH-01","productname":"Manx","unitcost":12.00,"status":"P","listprice":83.50,"attr1":"With tail","itemid":"EST-15"},
            {"productid":"FL-DLH-02","productname":"Persian","unitcost":12.00,"status":"P","listprice":23.50,"attr1":"Adult Female","itemid":"EST-16"},
            {"productid":"FL-DLH-02","productname":"Persian","unitcost":12.00,"status":"P","listprice":89.50,"attr1":"Adult Male","itemid":"EST-17"},
            {"productid":"AV-CB-01","productname":"Amazon Parrot","unitcost":92.00,"status":"P","listprice":63.50,"attr1":"Adult Male","itemid":"EST-18"}
        ];
        $(function(){
            var screenHeight = document.documentElement.clientHeight;
            var pageNum=1
            $("#dg").datagrid({
                header:'#hh',
                height:screenHeight,
                data:data,
                singleSelect:true,
                showFooter : true,
                //view:bufferview,
                rownumbers:true,
                pageSize:30
            })
            var scrollDiv = $(".datagrid-body").get(1);
            console.log(pushdata)

            $(scrollDiv).scroll(function(){
                console.log("gundong")
                var that=this;
                var cango=true;
                var scrollH=scrollDiv.scrollTop+scrollDiv.clientHeight
                if(scrollH==scrollDiv.scrollHeight&&cango==true){
                    for(var i=0;i<pushdata.length;i++) {
                        var row_data = {
                            itemid : pushdata[i].itemid,
                            productid :pushdata[i].productid,
                            listprice: pushdata[i].listprice,
                            unitcost : pushdata[i].unitcost,
                        };
                        $('#dg').datagrid('appendRow', row_data);
                    }
                    
                }
            })
        });
        //计算表格高度
        function setIframeHeight() {
            var screenHeight = document.documentElement.clientHeight;
            $(".table-body").height(screenHeight);
            $('#dg').datagrid("resize",{
                height: screenHeight
            }    
            );
        }
        //屏幕发生旋转重新计算高度
        window.addEventListener("resize",()=>{
            if(window.orientation===180||window.orientation===0){
                setIframeHeight();
            }if (window.orientation===90||window.orientation===-90) {
                setIframeHeight();
            }
        })
    </script>
</body>    
</html>


优缺点分析

EasyUI => ios:无问题;安卓:横向滚动表头抖动
JS => ios:无问题;安卓:垂直滚动表头抖动
两个table=> ios:无法横向滚动;安卓:无问题


来自:https://segmentfault.com/a/1190000019332336


链接: https://fly63.com/article/detial/3482

移动端如何强制页面横屏

有些机型有些app不能横屏:比如Android的微信就没有横屏模式,而ios的微信能开启横屏模式。解决办法就是在竖屏模式下,写一个横屏的div,然后设置rotate正(负)90度,把他旋转过来;而且如果用户切到横屏时,需要把rotate复原,要求也能正常展现。

ios移动端,js时间操作getTime(),getFullYear()等返回显示NaN的解决办法及原因

在做移动端时间转化为时间戳时,遇到了一个问题,安卓手机上访问时,能拿到时间戳,从而正确转换时间,而在iOS上缺不能正常显示,显示的时间为:NaN-NaN-NaN ,例如getTime()在ios上拿不到时间戳显示NaN

再聊移动端页面的适配

因为对于一枚前端而言,天天和页面打交道(H5页面),那么布局的活总是少不了,这也将面临不同终端的适配问题。不知道你是否和我一样,页面布局总是或多或少会有一些蛋疼的事情发生。

解决移动端点击穿透问题_h5实现移动端点击事件穿透的多种解决方案

移动端点透现象的解决办法:解决方案一:来得很直接github上有个fastclick可以完美解决;解决方案二:用touchend代替tap事件并阻止掉时A元素touchend的默认行为preventDefault(),从而阻止click事件的产生;解决方案三:延迟一定的时间(300ms+)来处理事件...

移动端开发注意问题

这篇文章主要总结移动端页面开发时需要注意的一些问题。比如:防止手机中网页放大和缩小、format-detection设置、上下拉动滚动条时卡顿慢 、禁止复制选中文本...

js实现移动端微信禁止字体被放大或缩小,防止排版错乱

由于微信webvie内置了调整字体大小的功能,如果用户调整了这一设置,就会导致了网页中的字体比原本的尺寸偏大或偏小,使得网页可能出现排版错乱,或者字体太小看不清的情况发生

阻止移动端浏览器点击图片会预览的几种方法

在移动端部分浏览器中点击了图片,变成了查看图片的效果,怎么防止img的图片被手机浏览器的图片查看器打开呢?下面整理了一些方法来实现:在img元素上添加 onclick=return false、背景图的方式插入、使用js事件阻止默认行为的方式

移动端300ms延迟的解决方法

移动端浏览器在派发点击事件的时候,通常会出现300ms左右的延迟。也就是说,当我们点击页面的时候移动端浏览器并不是立即作出反应,而是会等上一小会儿才会出现点击的效果。

移动web开发之视口viewport_浅谈移动端中的视口

在 PC 端,视口指的是浏览器的可视区域,其宽度和浏览器窗口的宽度保持一致。在 CSS 标准文档中,视口也被称为初始包含块,它是所有 CSS 百分比宽度推算的根源,给 CSS 布局限制了一个最大宽度。而移动端则较为复杂,它涉及到三个视口:布局视口(Layout Viewport)、视觉视口(Visual Viewport)和理想视口(Ideal Viewport)

手淘H5移动端适配方案flexible源码分析

随着技术的飞速发展,当前lib-flexible适配方案也在逐渐被更新的适配方案所替代,但是截止目前为止,还没有发现哪种方案能完全满足适配各种机型的需要,也会有一些小的问题。lib-flexible是目前用到的比较成熟的适配方案

点击更多...

内容以共享、参考、研究为目的,不存在任何商业目的。其版权属原作者所有,如有侵权或违规,请与小编联系!情况属实本人将予以删除!