6

我使用 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 - 但这似乎不是正确的解决方案。

4

3 回答 3

7

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.

Source: http://blog.jquery.com/2011/11/03/jquery-1-7-released/

When you console.log(e); inside your dragstop event handler you can see that all the x/y coordinate data is missing in jQuery 1.7; but it can be accessed in event.originalEvent.

UPDATE

If you look around in the event object you can find pageX/pageY in the origionalEvent property:

$('#test').html(e.originalEvent.pageX+','+e.originalEvent.pageY);

Here is an updated version of your jsbin: http://jsbin.com/ezulas/13/edit

于 2011-12-20T23:28:19.323 回答
1

我有同样的问题,并且正在搜索类似的线程很长一段时间。现在已经很晚了,但我希望这仍然可以让一些快乐的程序员免于绝望。我检查了我也在项目中使用的 jQuery UI Touch Punch 文件,发现它是如何引用 x/y 位置的。这最终对我有用:

$('.pages').on('touchstart vmousedown', function(e){
    var this_event_touch_start_Y    = e.originalEvent.changedTouches[0].clientY;
    var this_event_touch_start_X    = e.originalEvent.changedTouches[0].clientX;
});

作为参考,这里列出了我正在使用的所有 jQuery 文件:

  • jquery-3.1.1.min.js
  • jquery.touchSwipe.min.js
  • jquery-ui.min.js
  • jquery.ui.touch-punch.min.js
  • jquery.mobile-1.4.5.min.js
于 2017-04-26T12:09:47.630 回答
0

事件对象的 jQuery 文档中它说

以下属性也被复制到事件对象,但根据事件的不同,它们的某些值可能未定义:

altKey, 气泡, 按钮, 可取消, charCode, clientX, clientY, ctrlKey, currentTarget, data, detail, eventPhase, metaKey, offsetX, offsetY, originalTarget, pageX, pageY, prevValue, relatedTarget, screenX, screenY, shiftKey, target, view,哪个

这似乎符合你所说的。在您的情况下,您的事件没有定义 pageX 和 pageY。

于 2012-03-07T02:23:52.353 回答