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

时间:2021-05-26

1、前端页面
复制代码 代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="拖动排序Li或Table.aspx.cs" Inherits="拖动排序Li或Table" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://pute after each DOM insertion, NOT on mousemove
},0);

},

_clear: function(event, noPropagation) {

this.reverting = false;
// We delay all events that have to be triggered to after the point where the placeholder has been removed and
// everything else normalized again
var delayedTriggers = [], self = this;

// We first have to update the dom position of the actual currentItem
// Note: don't do it if the current item is already removed (by a user), or it gets reappended (see #4088)
if(!this._noFinalSort && this.currentItem[0].parentNode) this.placeholder.before(this.currentItem);
this._noFinalSort = null;

if(this.helper[0] == this.currentItem[0]) {
for(var i in this._storedCSS) {
if(this._storedCSS[i] == 'auto' || this._storedCSS[i] == 'static') this._storedCSS[i] = '';
}
this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper");
} else {
this.currentItem.show();
}

if(this.fromOutside && !noPropagation) delayedTriggers.push(function(event) { this._trigger("receive", event, this._uiHash(this.fromOutside)); });
if((this.fromOutside || this.domPosition.prev != this.currentItem.prev().not(".ui-sortable-helper")[0] || this.domPosition.parent != this.currentItem.parent()[0]) && !noPropagation) delayedTriggers.push(function(event) { this._trigger("update", event, this._uiHash()); }); //Trigger update callback if the DOM position has changed
if(!$.ui.contains(this.element[0], this.currentItem[0])) { //Node was moved out of the current element
if(!noPropagation) delayedTriggers.push(function(event) { this._trigger("remove", event, this._uiHash()); });
for (var i = this.containers.length - 1; i >= 0; i--){
if($.ui.contains(this.containers[i].element[0], this.currentItem[0]) && !noPropagation) {
delayedTriggers.push((function(c) { return function(event) { c._trigger("receive", event, this._uiHash(this)); }; }).call(this, this.containers[i]));
delayedTriggers.push((function(c) { return function(event) { c._trigger("update", event, this._uiHash(this)); }; }).call(this, this.containers[i]));
}
};
};

//Post events to containers
for (var i = this.containers.length - 1; i >= 0; i--){
if(!noPropagation) delayedTriggers.push((function(c) { return function(event) { c._trigger("deactivate", event, this._uiHash(this)); }; }).call(this, this.containers[i]));
if(this.containers[i].containerCache.over) {
delayedTriggers.push((function(c) { return function(event) { c._trigger("out", event, this._uiHash(this)); }; }).call(this, this.containers[i]));
this.containers[i].containerCache.over = 0;
}
}

//Do what was originally in plugins
if(this._storedCursor) $('body').css("cursor", this._storedCursor); //Reset cursor
if(this._storedOpacity) this.helper.css("opacity", this._storedOpacity); //Reset cursor
if(this._storedZIndex) this.helper.css("zIndex", this._storedZIndex == 'auto' ? '' : this._storedZIndex); //Reset z-index

this.dragging = false;
if(this.cancelHelperRemoval) {
if(!noPropagation) {
this._trigger("beforeStop", event, this._uiHash());
for (var i=0; i < delayedTriggers.length; i++) { delayedTriggers[i].call(this, event); }; //Trigger all delayed events
this._trigger("stop", event, this._uiHash());
}
return false;
}

if(!noPropagation) this._trigger("beforeStop", event, this._uiHash());

//$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node!
this.placeholder[0].parentNode.removeChild(this.placeholder[0]);

if(this.helper[0] != this.currentItem[0]) this.helper.remove(); this.helper = null;

if(!noPropagation) {
for (var i=0; i < delayedTriggers.length; i++) { delayedTriggers[i].call(this, event); }; //Trigger all delayed events
this._trigger("stop", event, this._uiHash());
}

this.fromOutside = false;
return true;

},

_trigger: function() {
if ($.widget.prototype._trigger.apply(this, arguments) === false) {
this.cancel();
}
},

_uiHash: function(inst) {
var self = inst || this;
return {
helper: self.helper,
placeholder: self.placeholder || $([]),
position: self.position,
absolutePosition: self.positionAbs, //deprecated
offset: self.positionAbs,
item: self.currentItem,
sender: inst ? inst.element : null
};
}

}));

$.extend($.ui.sortable, {
getter: "serialize toArray",
version: "1.7.1",
eventPrefix: "sort",
defaults: {
appendTo: "parent",
axis: false,
cancel: ":input,option",
connectWith: false,
containment: false,
cursor: 'auto',
cursorAt: false,
delay: 0,
distance: 1,
dropOnEmpty: true,
forcePlaceholderSize: false,
forceHelperSize: false,
grid: false,
handle: false,
helper: "original",
items: '> *',
opacity: false,
placeholder: false,
revert: false,
scroll: true,
scrollSensitivity: 20,
scrollSpeed: 20,
scope: "default",
tolerance: "intersect",
zIndex: 1000
}
});

})(jQuery);

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章