jquery实现的鼠标拖动排序Li或Table

2020-05-17 06:20:23易采站长站整理

this.offset.relative = this._getRelativeOffset();
}
var pageX = event.pageX;
var pageY = event.pageY;
/*
* – Position constraining –
* Constrain the position to a mix of grid, containment.
*/
if(this.originalPosition) { //If we are not dragging yet, we won’t check for options
if(this.containment) {
if(event.pageX – this.offset.click.left < this.containment[0]) pageX = this.containment[0] + this.offset.click.left;
if(event.pageY – this.offset.click.top < this.containment[1]) pageY = this.containment[1] + this.offset.click.top;
if(event.pageX – this.offset.click.left > this.containment[2]) pageX = this.containment[2] + this.offset.click.left;
if(event.pageY – this.offset.click.top > this.containment[3]) pageY = this.containment[3] + this.offset.click.top;
}
if(o.grid) {
var top = this.originalPageY + Math.round((pageY – this.originalPageY) / o.grid[1]) * o.grid[1];
pageY = this.containment ? (!(top – this.offset.click.top < this.containment[1] || top – this.offset.click.top > this.containment[3]) ? top : (!(top – this.offset.click.top < this.containment[1]) ? top – o.grid[1] : top + o.grid[1])) : top;
var left = this.originalPageX + Math.round((pageX – this.originalPageX) / o.grid[0]) * o.grid[0];
pageX = this.containment ? (!(left – this.offset.click.left < this.containment[0] || left – this.offset.click.left > this.containment[2]) ? left : (!(left – this.offset.click.left < this.containment[0]) ? left – o.grid[0] : left + o.grid[0])) : left;
}
}
return {
top: (
pageY // The absolute mouse position
– this.offset.click.top // Click offset (relative to the element)
– this.offset.relative.top // Only for relative positioned nodes: Relative offset from element to offset parent
– this.offset.parent.top // The offsetParent’s offset without borders (offset + border)
+ ($.browser.safari && this.cssPosition == ‘fixed’ ? 0 : ( this.cssPosition == ‘fixed’ ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ))
),
left: (
pageX // The absolute mouse position
– this.offset.click.left // Click offset (relative to the element)
– this.offset.relative.left // Only for relative positioned nodes: Relative offset from element to offset parent
– this.offset.parent.left // The offsetParent’s offset without borders (offset + border)
+ ($.browser.safari && this.cssPosition == ‘fixed’ ? 0 : ( this.cssPosition == ‘fixed’ ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))
)
};
},
_rearrange: function(event, i, a, hardRefresh) {
a ? a[0].appendChild(this.placeholder[0]) : i.item[0].parentNode.insertBefore(this.placeholder[0], (this.direction == ‘down’ ? i.item[0] : i.item[0].nextSibling));