HTML5 image drag event - ctrlKey remains false in Firefox 29

ぃ、小莉子 提交于 2020-01-04 08:08:52

问题


This works great in Chrome, but what do I need to change to make it work in Firefox?

e.ctrlKey remains false in FF:

$('img').on('drag', function(e){
    console.log('ctrlKey', e.ctrlKey);
});

http://jsfiddle.net/YF6UG/4/


回答1:


I think this is a bug in Firefox. After some digging in Bugzilla I found unconfirmed bug similar to your problem titled DragEnd event does not reflect real ctrl/shift/alt key status.




回答2:


It seems you can detect the ctrlKey in startdrag event, so as a workaround, you can just $(event.dataTransfer.setData('ctrlKey',event.ctrlKey) in startdrag. Then you can read it by $(event.dataTransfer.getData('ctrlKey') inside dragEnd event



来源:https://stackoverflow.com/questions/24016457/html5-image-drag-event-ctrlkey-remains-false-in-firefox-29

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