首頁 > web前端 > js教程 > 使表格的標題列可左右拉伸jquery插件封裝_jquery

使表格的標題列可左右拉伸jquery插件封裝_jquery

WBOY
發布: 2016-05-16 16:30:25
原創
1882 人瀏覽過

外掛名稱命名為:jquery.tableresize.js,程式碼如下:

複製程式碼 程式碼如下:

/*
Writen by mlcactus, 2014-11-24
這是我封裝的一個jquery插件,能夠使table的各列可以左右拉伸,從而使寬度變小或變大
用法:
單一table:$("#table_id").tableresize();   
頁所有table:$("table").tableresize();
*/
(function ($) {
    $.fn.tableresize = function () {
        var _document = $("body");
        $(this).each(function () {
            if (!$.tableresize) {
                $.tableresize = {};
            }
            var _table = $(this);
            //設定ID
            var id = _table.attr("id") || "tableresize_" (Math.random() * 100000).toFixed(0).toString();
            var tr = _table.find("tr").first(), ths = tr.children(), _firstth = ths.first();
            //設定暫時變因存放物件
            var cobjs = $.tableresize[id] = {};
            cobjs._currentObj = null, cobjs._currentLeft = null;
            ths.mousemove(function (e) {
                var _this = $(this);
var left = _this.offset().left, top = _this.offset().top, width = _this.width(), height = _this.height(), right = left width, bottom = top height, clientX = e .clientX, clientY = e.clientY;
             會                 if (cobjs._currentLeft || clientY > top && clientY                     _document.css("cursor", "e-resize");
                    if (!cobjs._currentLeft) {
                        if (leftside) {
                            cobjs._currentObj = _this.prev();                         }
                        else {
                            cobjs._currentObj = _this;
;
;                         }
                    }
                }
                else {
                    cobjs._currentObj = null;
                }
            });
            ths.mouseout(function (e) {
                if (!cobjs._currentLeft) {
                    cobjs._currentObj = null;
                    _document.css("字體", "自動");
                }
            });
            _document.mousedown(function (e) {
                if (cobjs._currentObj) {
                    cobjs._currentLeft = e.clientX;
                }
                否則{
                    cobjs._currentLeft = null;
                }
            });
            _document.mouseup(函數 (e) {
                if (cobjs._currentLeft) {
                    cobjs._currentObj.width(cobjs._currentObj.width() (e.clientX - cobjs._currentLeft));
                }
                cobjs._currentObj = null;
                cobjs._currentLeft = null;
                _document.css("字體", "自動");
            });
        });
    };
})(jQuery);  

頁面代碼為:

複製程式碼程式碼如下:

ttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
http://www.w3.org/1999/xhtml">

    標題>
    
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板