我使用 jQuery 并从 jqueryUI 中拖动。当我将 jQuery 从 1.6 更新到 1.7 时,clientX 和 pageX 属性从事件变量中消失。这是一个例子:
http://jsbin.com/ezulas/7/edit
如果在给定示例中 jQuery 版本更改为 1.6.4 - 它就会开始工作。使用最新版本 - clientX/Y 和 pageX/Y 均无法正常工作。我发现我可以使用 e=e.originalEvent - 但这似乎不是正确的解决方案。
最佳答案
event.layerX and event.layerY: We have removed these non-standard properties in version 1.7. Although we normally would have gone through a deprecation notice period for these, Chrome version 16 generates a flood of console warning messages on the page. Because of this, we decided to remove them immediately. On platforms that still support these properties, they are available through event.originalEvent.layerX and event.originalEvent.layerY.
来源:http://blog.jquery.com/2011/11/03/jquery-1-7-released/
当您在 dragstop
事件处理程序中使用 console.log(e);
时,您可以看到所有 x
/y
jQuery 1.7 中缺少坐标数据;但可以在 event.originalEvent
中访问它。
更新
如果您查看 event
对象,您可以在 origionalEvent
属性中找到 pageX
/pageY
:
$('#test').html(e.originalEvent.pageX+','+e.originalEvent.pageY);
这是您的 jsbin 的更新版本:http://jsbin.com/ezulas/13/edit
关于jQuery 1.7 clientX/pageX 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8583249/