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;
}
}
});