jQuery 1.7 clientX/pageX undefined

拟墨画扇 提交于 2019-12-04 06:04:12

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

I had the same problem and was searching similar threads for quite a while. It is now fairly late, but I hope this will still save some happy coders from despair. I checked the jQuery UI Touch Punch file that I was also using in my project and found how it refers to the x/y position. This is what eventually worked for me:

$('.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;
});

For reference, here a list of all jQuery files I am using:

  • 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

In the jQuery docs for Event Object it says

The following properties are also copied to the event object, though some of their values may be undefined depending on the event:

altKey, bubbles, button, cancelable, charCode, clientX, clientY, ctrlKey, currentTarget, data, detail, eventPhase, metaKey, offsetX, offsetY, originalTarget, pageX, pageY, prevValue, relatedTarget, screenX, screenY, shiftKey, target, view, which

Which seems to fit what you are saying. In your situation your event does not have pageX and pageY defined.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!