91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

HTML頁面如何實現table滾動條

發布時間:2020-10-26 11:40:02 來源:億速云 閱讀:1260 作者:小新 欄目:web開發

小編給大家分享一下HTML頁面如何實現table滾動條,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!

table scrollbar & header fixed

有很多頁面由于數據量過大,會產生橫縱滾動條。為了便于使用者觀看,我們要把表頭固定一下。根據這個需求寫了個demo來實現這個功能。

  • 主要解決了幾點問題:

  • 1.table實現橫縱滾動條

  • 2.table表頭固定

  • 3.table列寬自適應

  • 4.table內容不換行

主要代碼塊

css:

            .table-scroll {
                width: calc(100% - 5px);
                overflow-x: scroll;
                white-space: nowrap;
            }

            .table-scroll table {
                table-layout: fixed;
                width: calc(100% - 10px);
                background-color:darkseagreen ;
            }

            .table-scroll thead {
                display: table-row;
                background-color: bisque;
            }

            .table-scroll tbody {
                overflow-y: scroll;
                overflow-x: hidden;
                display: block;
                height: calc(100vh - 300px);
            }

            .table-scroll th,td {
                width: 160px;
                overflow: hidden;
                text-overflow: ellipsis;
                min-width: 160px;
                border: 1px solid #808080;
            }

            h5, h6 {
                color: cornflowerblue;
            }

js:

    $(function() {
            $('.table-scroll').scroll(function() {
                  $('.table-scroll table').width($('.table-scroll').width() 
                  + $('.table-scroll').scrollLeft());
                });

                var tableTdWidths = new Array();
            var tableWidth = 0;
            var tableTr0Width = 0;
            var tableThNum = 0;
            var tableTr1Width = 0;

                tableWidth = $('.table-scroll table').css('width').replace('px','');
                tableThNum = $('.table-scroll tr:eq(0)').children('th').length;            if ($('.table-scroll tr').length == 1) { // header only                if (tableWidth > tableTr0Width) {
                    $('.table-scroll tr:eq(0)').children('th').each(function(i){
                        $(this).width(parseInt(($(this).css('width').replace('px','')) 
                        + parseInt(Math.floor((tableWidth - tableTr0Width) / tableThNum))) + 'px');
                    });
                }
            } else { // header and body
                tableTr1Width = $('.table-scroll tr:eq(1)').css('width').replace('px','');
                    $('.table-scroll tr:eq(1)').children('td').each(function(i){
                    tableTdWidths[i]=$(this).css('width').replace('px','');
                });
                $('.table-scroll tr:eq(0)').children('th').each(function(i) {            if(parseInt($(this).css('width').replace('px', '')) >
                parseInt(tableTdWidths[i])) {
                tableTdWidths[i] = $(this).css('width').replace('px','');
                    }
                });                if (tableWidth > tableTr1Width) {
                    //set all th td width
                    $('.table-scroll tr').each(function(i){
                            $(this).children().each(function(j){
                                $(this).css('min-width',(parseInt(tableTdWidths[j]) 
                                + parseInt(Math.floor((tableWidth - tableTr1Width) / 
                                tableThNum))) + 'px');
                            });
                    });
                } else {
                    //method 1 : set all th td width
                    $('.table-scroll tr').each(function(i){
                            $(this).children().each(function(j){
                                $(this).css('min-width',tableTdWidths[j] + 'px');
                            });
                    });
                }
            }
            });

html:

    <body>
        <h5>完成效果:1.固定表頭 2.table橫縱滾動條 3.table列寬自適應 4.table內容不換行</h5>
        <p class="table-scroll">
            <table>
                <thead>
                    <th>title1</th>
                    <th>title1</th>
                    <th>title1</th>
                    <th>title1</th>
                    <th>title1</th>
                    <th>title1</th>
                    <th>title1</th>
                    <th>title1</th>
                    <th>title1</th>
                    <th>title1</th>
                    <th>title1</th>
                    <th>title1</th>
                    <th>title1</th>
                    <th>title1</th>
                    <th>title1</th>
                    <th>title1</th>
                </thead>
                <tbody>
                    <tr>
                        <td>1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>2</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>3</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>4</td>
                        <td>body1 body1 body1 body1 body1 body1 body1 body1 body1 body1 body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1 body1 body1 body1 body1 body1 body1 body1 body1 body1 body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>5</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>6</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>7</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>8</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>9</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>10</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>11</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>12</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>13</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>14</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>15</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>16</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>17</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>18</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>19</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>20</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>21</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>22</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>23</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>24</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>25</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>26</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>27</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>28</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>28</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>29</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                    <tr>
                        <td>30</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                        <td>body1</td>
                    </tr>
                </tbody>
            </table>
        </p>
    </body>

網上也有很多的例子,但是實現的效果不是想要的,自己工作需要做了一下,畫面不好看,重點看效果,如有問題請指正!

看完了這篇文章,相信你對HTML頁面如何實現table滾動條有了一定的了解,想了解更多相關知識,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

泰来县| 镇巴县| 定边县| 江油市| 洱源县| 溧水县| 贞丰县| 谷城县| 兴义市| 旌德县| 鹤庆县| 乐安县| 永仁县| 光泽县| 陵川县| 奉化市| 滨州市| 张掖市| 昌江| 房山区| 蚌埠市| 蒲城县| 娄烦县| 明溪县| 开原市| 泰顺县| 普兰店市| 扶沟县| 梁山县| 虹口区| 丹东市| 保亭| 攀枝花市| 双峰县| 新民市| 安宁市| 招远市| 新源县| 漳平市| 施秉县| 阜新市|