Table Drag resize column wide jquery code (1/2)

Source: Internet
Author: User

Table Drag resize column wide jquery code
In order to be able to use all pages that require this effect, and do not need to change any HTML on the page, I integrate all the code into $ (document). Ready (function () {}); , and write a standalone JS file.
Simulates a vertical bar with a 1-pixel-wide Div, added to the BODY element after the page is loaded

$ (document). Ready (function () {
$ (' body '). Append ("<div id=" line "style=" width:1px;height:200px;border-left:1px solid #00000000; Position: Absolute;display:none "></div>");
});

The next step is to move the mouse over the vertical border of the table to the mouse variant, at first I considered adding a small block level element to the header to trigger the MouseMove and Mouseo tutorial UT events, but for simplicity I chose to add the event for the entire table header.

Handling mouse variants in the MouseMove event of th
$ ("th"). Bind ("MouseMove", function (event) {
var th = $ (this);
Do not add an effect to the first column and last column
if (Th.prevall (). length <= 1 | | th.nextall (). length < 1) {
Return
}
var left = Th.offset (). Left;
The effect is triggered by 4 pixels from the header border line
if (Event.clientx-left < 4 | | (Th.width ()-(Event.clientx-left)) < 4) {
Th.css Tutorial ({' cursor ': '/web/page/frameset/images/splith.cur '});
Modify the path for your mouse icon
}
else {
TH.CSS ({' cursor ': ' Default '});
}
});

When the mouse is pressed, the vertical bar is displayed, the height is set, the CSS property is positioned, and the th object that is currently changing the width of the column is recorded, because a border line is shared by two th, where the previous th object is always taken.

$ ("th"). Bind ("MouseDown", function (event) {
var th = $ (this);
The same judgment as in the MouseMove function
if (Th.prevall (). length < 1 | th.nextall (). length < 1) {
Return
}
var pos = Th.offset ();
if (Event.clientx-pos.left < 4 | | (Th.width ()-(Event.clientx-pos.left)) < 4) {
var height = th.parent (). Parent (). height ();
var top = Pos.top;
$ ("#line"). CSS ({"Height": height, "top": Top, "left": event. Clientx, "Display": "});
Global variable that represents whether the current column is being resized
Linemove = true;
Always take the previous th object
if (Event.clientx-pos.left < Th.width ()/2) {
Currth = Th.prev ();
}
else {
Currth = th;
}
}
});

Home 1 2 last page

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.