You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.3 KiB
Plaintext

11 months ago
/*
* 窗体拖动方法
* 参数说明parentWrapSelector容器选择器必要 activeSelector拾起状态类名必要
*/
$.fn.dragTools = function(parentWrapSelector,activeSelector){
$(this).mousedown(function(e) {
var dom = $(this);
var positionDiv = $(this).offset();
var distenceX = e.pageX - positionDiv.left;
var distenceY = e.pageY - positionDiv.top;
var block = dom.parents(parentWrapSelector).eq(0);
block.addClass(activeSelector)
$(document).mousemove(function(e) {
var x = e.pageX - distenceX;
var y = e.pageY - distenceY - 0*rem;
if (x < 0) {
x = 0;
} else if (x > $(document).width() - block.outerWidth(true)) {
x = $(document).width() - block.outerWidth(true);
}
if (y < 0) {
y = 0;
} else if (y > $(document).height() - block.outerHeight(true) - 0*rem) {
y = $(document).height() - block.outerHeight(true) - 0*rem;
}
block.css({
'left': x + 'px',
'top': y + 'px'
});
});
$(document).mouseup(function() {
$(document).off('mousemove');
block.removeClass(activeSelector)
});
});
};