Made a jquery plugin so that the table header column can be stretched left and right

Source: Internet
Author: User

Sample Download

Plug-in name named: Jquery.tableresize.js, the code is as follows:

/*writen by Mlcactus, 2014-11-24 This is a jquery plugin I've encapsulated that allows columns of table to stretch left and right, making the width smaller or larger: a single table:$ ("#table_id").    Tableresize ();         Page All table:$ ("table"). Tableresize (); */(function ($) {$.fn.tableresize = function () {var _document = $ ("body");            $ (this). each (function () {if (!$.tableresize) {$.tableresize = {};            } var _table = $ (this); Set 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 ();            Set temporary variable storage object 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 + W Idth, bottom = top + height, ClientX = e.cliEntx, ClientY = E.clienty; var leftside =!_firstth.is (_this) && math.abs (Left-clientx) <= 5, rightside = Math.Abs (Right-clientx) <                = 5;                    if (Cobjs._currentleft | | ClientY > Top && ClientY < bottom && (leftside | | rightside)) {                    _DOCUMENT.CSS ("cursor", "e-resize"); if (!cobjs._currentleft) {if (leftside) {cobjs._currentobj = _this.pre                        V ();                        } else {cobjs._currentobj = _this;                }}}} else {cobjs._currentobj = null;            }            });                    Ths.mouseout (function (e) {if (!cobjs._currentleft) {cobjs._currentobj = null;                _DOCUMENT.CSS ("cursor", "Auto");            }            }); _document.MouseDown (function (e) {if (cobjs._currentobj) {cobjs._currentleft = E.clientx;                } else {cobjs._currentleft = null;            }            }); _document.mouseup (function (e) {if (cobjs._currentleft) {cobjs._currentobj.width (COBJS                . _currentobj.width () + (e.clientx-cobjs._currentleft));                } cobjs._currentobj = null;                Cobjs._currentleft = null;            _DOCUMENT.CSS ("cursor", "Auto");        });    }); };})    (JQuery);

The page code is:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

The

makes a jquery plugin so that the title column of the table can be stretched left and right

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.