我在 Ajaxian 上找到了这个片段,但我似乎无法使用 cursor.y(或 cursor.x)作为变量,并且当这样调用函数时它似乎不起作用。是否存在语法问题或其他问题?
function getPosition(e) {
e = e || window.event;
var cursor = {x:0, y:0};
if (e.pageX || e.pageY) {
cursor.x = e.pageX;
cursor.y = e.pageY;
}
else {
cursor.x = e.clientX +
(document.documentElement.scrollLeft ||
document.body.scrollLeft) -
document.documentElement.clientLeft;
cursor.y = e.clientY +
(document.documentElement.scrollTop ||
document.body.scrollTop) -
document.documentElement.clientTop;
}
return cursor;
}
如果可能的话,我宁愿不使用 jQuery UI,因为我一直认为 jQuery 和库对于大多数 JS 编程来说有点矫枉过正。