Javascript 将两个数组发送到使用document.attachEvent(“onmousemove”,dragGo)运行的函数
我想将Javascript 将两个数组发送到使用document.attachEvent(“onmousemove”,dragGo)运行的函数,javascript,arrays,addeventlistener,Javascript,Arrays,Addeventlistener,我想将all\u dragable\u obj\u left和all\u dragable\u obj\u top数组传递到dragGo函数中: 一,document.attachEvent(“onmousemove”,dragGo)和 二,文档.addEventListener(“mousemove”,dragGo,true) 代码如下: function dragStart(event, id) { var el; var x, y; if (id)
all\u dragable\u obj\u left
和all\u dragable\u obj\u top
数组传递到dragGo
函数中:
一,<代码>document.attachEvent(“onmousemove”,dragGo)代码>和
二,<代码>文档.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);
}
}
一,。首先
document.attachEvent("onmousemove", function(e){
dragGo(e, all_dragable_obj_left, all_dragable_obj_top);
});
二,。第二
document.addEventListener("mousemove", function(e){
dragGo(e, all_dragable_obj_left, all_dragable_obj_top);
}, true);
三,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();
}
请发布更多代码,以及附加事件的代码。