var mx;
var my;
var dragStatus;
//开始拖动
function _startDrag(e){ mx = window.event ? (e.clientX + document.body.scrollLeft) : e.pageX;
my = window.event ? (e.clientY + document.body.scrollTop) : e.pageY;
if (!window.captureEvents) {
$('.floatDivTit').get(0).setCapture();
}else {
//window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
}
dragStatus = true;
}
//停止拖动
function _stopDrag(){
mx;
my;
dragStatus = false;
if (!window.captureEvents) {
$('.floatDivTit').get(0).releaseCapture();
}else {
//window.releaseEvents(Event.MOUSEMOVE|Event.MOUSEUP);
}
$('#mx').val(0);
}
//拖动
function _drag(e){
if( true == dragStatus ){
mouseX = window.event ? (e.clientX + document.body.scrollLeft) : e.pageX;
mouseY = window.event ? (e.clientY + document.body.scrollTop) : e.pageY; var x = mouseX-mx;
var y = mouseY-my;
lf = parseInt($('#floatDiv').offset().left)+x;
tp = parseInt($('#floatDiv').offset().top)+y;
$('#floatDiv').css('left',lf);
$('#floatDiv').css('top',tp);
mx = mouseX;
my = mouseY;
} }
在ie下也有同样的问题,不过通过setCapture 可以解决。
在火狐下不能拖快了,否则感觉div掉了一样。
在ff下面拖块了,感觉鼠标就脱离层了。
一般在mousedown的时候绑定mousemove事件,mouseup的时候移除绑定
dd: function(Cursorconfig) {
var sthis = this;
var doc = document;
doc.state = false;
sthis.dom.ddinit = true;
sthis.dom.Cursorconfig = Cursorconfig || "";
doc.resize = false;
doc.CursorStr = "";
function find(el) {
for (; el != null && typeof el.ddinit != "boolean"; ) {
if (el == null || el == doc.body) return doc.body;
el = el.parentNode
}
if (el == null || el == doc.body) return doc.body;
return el;
}
this.bind("mousedown", function(e) {
doc.state = true;
doc.tpos = { x: 0, y: 0 };
doc.tpos.x = SS.event.pos(e).x - sthis.pos().left;
doc.tpos.y = SS.event.pos(e).y - sthis.pos().top;
doc.ddobj = sthis;
// doc.body.onselectstart = function() { return false; };
})
.bind("mouseup", function() {
SS(this).css("cursor", "default");
});
doc.onmouseup = function() {
doc.state = false;
//doc.body.onselectstart = function() { };
doc.resize = false;
};
doc.onmousemove = function(e) {
var obj = SS.event.pos(e);
var str = "";
var targetobj = SS(find(SS.event.target(e)));
if (typeof targetobj.dom.ddinit == "boolean" && doc.resize == false) {
if (Math.abs(obj.y - targetobj.pos().top - targetobj.height()) < 10) str += "s";
if (Math.abs(obj.x - targetobj.pos().left - targetobj.width()) < 10) str += "e";
if (str == "") str = "default"; else if (targetobj.dom.Cursorconfig.indexOf(str) != -1) { str += "-resize"; } else { str = "default"; }
targetobj.css("cursor", str);
}
if (doc.state == true) {
if (doc.resize || (str != "" && str != "default" && str != "move")) {
ww = obj.x - doc.ddobj.pos().left;
hh = obj.y - doc.ddobj.pos().top;
ww = ww > 0 ? ww : 0; hh = hh > 0 ? hh : 0;
if (doc.resize == false) { doc.resize = true; doc.CursorStr = str; }
switch (doc.CursorStr) {
case "e-resize": doc.ddobj.css({ "width": ww + "px", "overflow": "hidden" }); break;
case "s-resize": doc.ddobj.css({ "height": hh + "px", "overflow": "hidden" }); break;
case "se-resize": doc.ddobj.css({ "height": hh + "px", "width": ww + "px", "overflow": "hidden" }); break;
}
}
else {
doc.ddobj.css({ position: "absolute", top: obj.y - doc.tpos.y + "px", left: obj.x - doc.tpos.x + "px", Zindex: 100000 });
}
}
};
this.bind("mouseout", function() { });
this.s("input,textarea").each(function() {
SS(this).bind("mousedown", function(e) {
SS.event.stopPop(e);
});
}); }