我想将all_dragable_obj_left
和all_dragable_obj_top
数组传递给dragGo
函数:
1。 document.attachEvent("onmousemove", dragGo);
和
2。 document.addEventListener("mousemove", dragGo, true);
。
以下是代码:
function dragStart(event, id) {
var el;
var x, y;
if (id)
dragObj.elNode = document.getElementById(id);
else {
if (browser.isIE)
dragObj.elNode = window.event.srcElement;
if (browser.isNS)
dragObj.elNode = event.target;
if (dragObj.elNode.nodeType == 3)
dragObj.elNode = dragObj.elNode.parentNode;
}
if (browser.isIE) {
x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
}
if (browser.isNS) {
x = event.clientX + window.scrollX;
y = event.clientY + window.scrollY;
}
// Save starting positions of cursor and element.
$("img[class=obj_mov]").each(function () {
all_dragable_obj_left.push(parseInt($(this).css("left"), 10));
all_dragable_obj_top.push(parseInt($(this).css("top"), 10));
});
dragObj.cursorStartX = x;
dragObj.cursorStartY = y;
if (browser.isIE) {
document.attachEvent("onmousemove", dragGo);
document.attachEvent("onmouseup", dragStop);
window.event.cancelBubble = true;
window.event.returnValue = false;
}
if (browser.isNS) {
document.addEventListener("mousemove", dragGo, true);
document.addEventListener("mouseup", dragStop, true);
event.preventDefault();
}
}
function dragGo(event) {
var x, y;
if (browser.isIE) {
x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
}
if (browser.isNS) {
x = event.clientX + window.scrollX;
y = event.clientY + window.scrollY;
}
var i = 0;
i = 0;
$("img[class=obj_mov]").each(function () {
$(this).css("left",all_dragable_obj_left[i]+ x - dragObj.cursorStartX);
$(this).css("top",all_dragable_obj_top[i]+ y - dragObj.cursorStartY);
i++;
});
if (browser.isIE) {
window.event.cancelBubble = true;
window.event.returnValue = false;
}
if (browser.isNS)
event.preventDefault();
}
function dragStop(event) {
dragObj.elNode = null;
if (browser.isIE) {
document.detachEvent("onmousemove", dragGo);
document.detachEvent("onmouseup", dragStop);
}
if (browser.isNS) {
document.removeEventListener("mousemove", dragGo, true);
document.removeEventListener("mouseup", dragStop, true);
}
}
答案 0 :(得分:0)
1。第一
document.attachEvent("onmousemove", function(e){
dragGo(e, all_dragable_obj_left, all_dragable_obj_top);
});
2。第二
document.addEventListener("mousemove", function(e){
dragGo(e, all_dragable_obj_left, all_dragable_obj_top);
}, true);
3。 dargGo()
功能
function dragGo(event, all_dragable_obj_left, all_dragable_obj_top) {
var x, y;
if (browser.isIE) {
x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
}
if (browser.isNS) {
x = event.clientX + window.scrollX;
y = event.clientY + window.scrollY;
}
var i = 0;
i = 0;
$("img[class=obj_mov]").each(function () {
$(this).css("left",all_dragable_obj_left[i]+ x - dragObj.cursorStartX);
$(this).css("top",all_dragable_obj_top[i]+ y - dragObj.cursorStartY);
i++;
});
if (browser.isIE) {
window.event.cancelBubble = true;
window.event.returnValue = false;
}
if (browser.isNS)
event.preventDefault();
}