<em id="09ttv"></em>
    <sup id="09ttv"><pre id="09ttv"></pre></sup>
    <dd id="09ttv"></dd>

        • datatable 拖動(dòng)列寬 鼠標(biāo)拖動(dòng)列寬

          2021-7-23    前端達(dá)人


          本篇博客所用到的技術(shù)也是從別的博客學(xué)習(xí)到的,但目前找不到那篇博客的鏈接了。

          1.普通表格實(shí)現(xiàn)拖動(dòng)列寬

          var tabSize = tabSize || {}; tabSize.init = function (id) { //用來存儲當(dāng)前更改寬度的Table Cell,避免快速移動(dòng)鼠標(biāo)的問題 var tTD; // 獲取需要修改列寬的表格 var table = document.getElementById(id); var headTh = table.rows[0]; for (j = 0; j < headTh.cells.length; j++) { headTh.cells[j].onmousedown = function () { //記錄單元格 tTD = this; if (event.offsetX > tTD.offsetWidth - 10) { tTD.mouseDown = true; tTD.oldX = event.x; tTD.oldWidth = tTD.offsetWidth; } }; headTh.cells[j].onmouseup = function () { //結(jié)束寬度調(diào)整 if (tTD == undefined) tTD = this; tTD.mouseDown = false; tTD.style.cursor = 'default'; }; headTh.cells[j].onmousemove = function () { //更改鼠標(biāo)樣式 if (event.offsetX > this.offsetWidth - 10) this.style.cursor = 'col-resize'; else this.style.cursor = 'default'; //取出暫存的Table Cell if (tTD == undefined) tTD = this; //調(diào)整寬度 if (tTD.mouseDown != null && tTD.mouseDown == true) { tTD.style.cursor = 'default'; if (tTD.oldWidth + (event.x - tTD.oldX) > 0) tTD.width = tTD.oldWidth + (event.x - tTD.oldX); //調(diào)整列寬 tTD.style.width = tTD.width + 'px'; tTD.style.cursor = 'col-resize'; // 調(diào)整滾動(dòng)表格的每個(gè)cell for (k = 0; k < table.rows.length; k++) { table.rows[k].cells[tTD.cellIndex].style.width = tTD.style.width; } } }; } }; // 調(diào)用 // 鼠標(biāo)拖動(dòng)列寬 setTimeout(function () { // 1.html代碼里就是一個(gè)普通的table元素 // 2.傳入table元素的id tabSize.init('documentList'); }, 600); 
          
          • 1
          • 2
          • 3
          • 4
          • 5
          • 6
          • 7
          • 8
          • 9
          • 10
          • 11
          • 12
          • 13
          • 14
          • 15
          • 16
          • 17
          • 18
          • 19
          • 20
          • 21
          • 22
          • 23
          • 24
          • 25
          • 26
          • 27
          • 28
          • 29
          • 30
          • 31
          • 32
          • 33
          • 34
          • 35
          • 36
          • 37
          • 38
          • 39
          • 40
          • 41
          • 42
          • 43
          • 44
          • 45
          • 46
          • 47
          • 48
          • 49
          • 50
          • 51
          • 52
          • 53
          • 54
          • 55
          • 56

          在這里插入圖片描述
          在這里插入圖片描述
          在這里插入圖片描述

          2.datatable實(shí)現(xiàn)鼠標(biāo)拖動(dòng)列寬

          1. 項(xiàng)目中用到datatable插件的地方,都是需要上下滾動(dòng)的;而datatable插件實(shí)現(xiàn)上下滾動(dòng),是生成了兩個(gè)div各包含了一個(gè)table,一個(gè)表格里只包含thead并且固定住(類:dataTables_scrollHead),另一個(gè)實(shí)現(xiàn)table內(nèi)容滾動(dòng)(類:dataTables_scrollBody) 。
          2. 那么,若要實(shí)現(xiàn)鼠標(biāo)拖動(dòng)列寬的話,則需要:表頭綁定鼠標(biāo)事件→事件觸發(fā)時(shí)兩個(gè)表格的對應(yīng)列的寬度都要改變
          3. 若這個(gè)datatable表格原本沒有滾動(dòng)條的話,在鼠標(biāo)拖動(dòng)列寬的時(shí)候,會出現(xiàn)滾動(dòng)條,其中,datatable定義時(shí),“scrollX”: true在這里插入圖片描述
            在這里插入圖片描述
          var tabSize = tabSize || {}; tabSize.init = function (id,headTableWrapperId) { //用來存儲當(dāng)前更改寬度的Table Cell,避免快速移動(dòng)鼠標(biāo)的問題 var tTD; // 獲取需要修改列寬的表格 var table = document.getElementById(id); // 獲取固定頭部的表格 var tableHead = $('#'+ headTableWrapperId + ' .dataTables_scrollHeadInner table')[0]; // 獲取表格頭部th var headTh = tableHead.rows[0]; for (j = 0; j < headTh.cells.length; j++) { headTh.cells[j].onmousedown = function () { //記錄單元格 tTD = this; if (event.offsetX > tTD.offsetWidth - 10) { tTD.mouseDown = true; tTD.oldX = event.x; tTD.oldWidth = tTD.offsetWidth; } }; headTh.cells[j].onmouseup = function () { //結(jié)束寬度調(diào)整 if (tTD == undefined) tTD = this; tTD.mouseDown = false; tTD.style.cursor = 'default'; }; headTh.cells[j].onmousemove = function () { //更改鼠標(biāo)樣式 if (event.offsetX > this.offsetWidth - 10) this.style.cursor = 'col-resize'; else this.style.cursor = 'default'; //取出暫存的Table Cell if (tTD == undefined) tTD = this; //調(diào)整寬度 if (tTD.mouseDown != null && tTD.mouseDown == true) { tTD.style.cursor = 'default'; if (tTD.oldWidth + (event.x - tTD.oldX) > 0) tTD.width = tTD.oldWidth + (event.x - tTD.oldX); //調(diào)整列寬 tTD.style.width = tTD.width + 'px'; tTD.style.cursor = 'col-resize'; // 調(diào)整滾動(dòng)表格的每個(gè)cell for (k = 0; k < table.rows.length; k++) { table.rows[k].cells[tTD.cellIndex].style.width = tTD.style.width; } } }; } }; // 鼠標(biāo)拖動(dòng)列寬 setTimeout(function () { // 參數(shù):1.table元素的id, // 2.datatable插件生成的最外層div的id,F(xiàn)12可查看到 tabSize.init('cfcPlanListIn','cfcPlanListIn_wrapper'); }, 2000); 
          
          • 1
          • 2
          • 3
          • 4
          • 5
          • 6
          • 7
          • 8
          • 9
          • 10
          • 11
          • 12
          • 13
          • 14
          • 15
          • 16
          • 17
          • 18
          • 19
          • 20
          • 21
          • 22
          • 23
          • 24
          • 25
          • 26
          • 27
          • 28
          • 29
          • 30
          • 31
          • 32
          • 33
          • 34
          • 35
          • 36
          • 37
          • 38
          • 39
          • 40
          • 41
          • 42
          • 43
          • 44
          • 45
          • 46
          • 47
          • 48
          • 49
          • 50
          • 51
          • 52
          • 53
          • 54
          • 55
          • 56
          • 57

          在這里插入圖片描述
          在這里插入圖片描述

          藍(lán)藍(lán)設(shè)計(jì)建立了UI設(shè)計(jì)分享群,每天會分享國內(nèi)外的一些優(yōu)秀設(shè)計(jì),如果有興趣的話,可以進(jìn)入一起成長學(xué)習(xí),請掃碼藍(lán)小助,報(bào)下信息,藍(lán)小助會請您入群。歡迎您加入噢~~希望得到建議咨詢、商務(wù)合作,也請與我們聯(lián)系。

          截屏2021-05-13 上午11.41.03.png


          文章來源:csdn 作者:阿晏

          分享此文一切功德,皆悉回向給文章原作者及眾讀者.
          免責(zé)聲明:藍(lán)藍(lán)設(shè)計(jì)尊重原作者,文章的版權(quán)歸原作者。如涉及版權(quán)問題,請及時(shí)與我們?nèi)〉寐?lián)系,我們立即更正或刪除。

          藍(lán)藍(lán)設(shè)計(jì)www.sdgs6788.com )是一家專注而深入的界面設(shè)計(jì)公司,為期望卓越的國內(nèi)外企業(yè)提供卓越的UI界面設(shè)計(jì)、BS界面設(shè)計(jì) 、 cs界面設(shè)計(jì) 、 ipad界面設(shè)計(jì) 、 包裝設(shè)計(jì) 、 圖標(biāo)定制 、 用戶體驗(yàn) 、交互設(shè)計(jì)、 網(wǎng)站建設(shè) 平面設(shè)計(jì)服務(wù)

          日歷

          鏈接

          個(gè)人資料

          存檔

          国产69精品久久久久9999APGF | 一级做a爰片久久毛片毛片| 国产精品久久精品| 国内精品久久久久久野外| 色综合久久综精品| 久久综合成人网| 狠狠综合久久综合88亚洲| 国产成人精品久久免费动漫| 亚洲狠狠综合久久| 伊人色综合久久天天网| 男女久久久国产一区二区三区| 久久久久四虎国产精品| 久久强奷乱码老熟女网站| 无码国产69精品久久久久网站| 99久久人妻无码精品系列| 久久久精品久久久久久| 久久亚洲AV成人出白浆无码国产| 久久精品国产一区| 久久久噜噜噜久久中文字幕色伊伊| 99久久超碰中文字幕伊人| 久久久久久毛片免费看| 久久久久亚洲av无码专区| 久久久久免费视频| 69久久精品无码一区二区| 久久久久久久波多野结衣高潮 | 久久亚洲AV无码西西人体| 国产成年无码久久久免费| 久久精品国产亚洲精品| 精品久久无码中文字幕| 亚洲精品高清一二区久久| 久久综合久久综合久久| 日韩人妻无码一区二区三区久久| 精品国产综合区久久久久久| 久久这里只有精品18| 亚洲精品WWW久久久久久| 久久国产三级无码一区二区| 久久精品国产亚洲AV麻豆网站| 无码任你躁久久久久久| 国产精品日韩深夜福利久久| 99久久99这里只有免费费精品| 国产69精品久久久久APP下载|