jquery实现页面控件拖动效果js代码

时间:2024-01-05 20:10:56

;(function($) {
var DragPanelId = "divContext";
var _idiffx = 0;
var _idiffy = 0;
var _Div = null;
$.extend({

AttachDrag: function(dragId) {
if (dragId)
$._Div = document.getElementById(dragId);
else
$._Div = document.getElementById($.DragPanelId);
document.body.onmousedown = $._handleMouseDown;

},
_handleMouseDown: function() {
var oEvent = window.event;
if ($._Div) {
$._idiffx = oEvent.clientX - $._Div.offsetLeft;
$._idiffy = oEvent.clientY - $._Div.offsetTop;
document.body.onmousemove = $._handleMouseMove;
document.body.onmouseup = $._handleMouseUp;
}
},
_handleMouseMove: function() {
var oEvent = window.event;
$._Div.style.left = oEvent.clientX - $._idiffx;
$._Div.style.top = oEvent.clientY - $._idiffy;
$._Div.style.cursor = "move";
},
_handleMouseUp: function() {
document.body.onmousemove = null;
document.body.onmouseup = null;
$._Div.style.cursor = "default";
}
});
}
)(jQuery)