JS部分:
//html 元素 拖拽效果js类 --start--
function Drag(){
//初始化
this.initialize.apply(this, arguments)
}
Drag.prototype = {
//初始化
initialize : function (drag, options)
{
this.drag = this.$(drag);
this._x = this._y = 0;
this._moveDrag = this.bind(this, this.moveDrag);
this._stopDrag = this.bind(this, this.stopDrag);
this.setOptions(options);
this.handle = this.$(this.options.handle);
this.maxContainer = this.$(this.options.maxContainer);
this.maxTop = Math.max(this.maxContainer.clientHeight, this.maxContainer.scrollHeight) - this.drag.offsetHeight;
this.maxLeft = Math.max(this.maxContainer.clientWidth, this.maxContainer.scrollWidth) - this.drag.offsetWidth;
this.limit = this.options.limit;
this.lockX = this.options.lockX;
this.lockY = this.options.lockY;
this.lock = this.options.lock;
this.onStart = this.options.onStart;
this.onMove = this.options.onMove;
this.onStop = this.options.onStop;
//this.handle.style.cursor = "move";
this.changeLayout();
this.addHandler(this.handle, "mousedown", this.bind(this, this.startDrag))
},
changeLayout : function ()
{
this.drag.style.top = this.drag.offsetTop + "px";
this.drag.style.left = this.drag.offsetLeft + "px";
this.drag.style.position = "absolute";
this.drag.style.margin = "0"
},
startDrag : function (event)
{
var event = event || window.event;
this._x = event.clientX - this.drag.offsetLeft;