Table columns can be dragged to change the column sizes (when used to replace all youElement say you want to add elements to this effect, the need is jqery selector format, such as: $ ( "table th / td"))

$ (function () { 
var = isMouseDown to false;
var currentTh = null;
youElement.bind ({
mouseDown: function (E) {
var $ $ = TH (the this);
. = $ th.offset left var () left; / / element from the left
var rightPos = left + $ th.outerWidth ();
IF (rightPos -. 4 <= e.pageX && e.pageX <= rightPos) {
isMouseDown = to true;
currentTh TH = $;
youElement.css ( 'Cursor ',' of a resize-EW ');

// create a mask layer, to prevent mouseup event bubbling other elements are blocked, resulting in body mouseup event can not be captured, leading to drag can not stop
var bodyWidth = $ (' body ' ) width. ();
var bodyHeight = $ ( 'body') height ().;
















if (! isMouseDown) {// is not canceled when the mouse click a particular mouse style
ele.css ( "Cursor", "Auto");
}
}
});

// change the size of the
IF (currentTh = null) {!
IF ( isMouseDown) {// the mouse is pressed, starts moving
var left = currentTh.offset () left;.
var paddingBorderLen = currentTh.outerWidth () - currentTh.width ();
currentTh.width ((e.pageX - left - paddingBorderLen ) + 'PX');
var currentTh = S [0];
! the while (s.tagName = "TABLE") {
S = s.parentNode;
}
for (let i = 0; i <s.rows.length ; i++) {
$(s.rows[i].cells[currentTh[0].cellIndex]).width((e.pageX - left - paddingBorderLen) + 'px');
}
}
}
},
mouseup: function (e) {
isMouseDown = false;
currentTh = null;
youElement.css('cursor', 'auto');
$('#mask').remove();
}
});
});

Guess you like

Origin www.cnblogs.com/fei-le/p/11583730.html