问题描述
我正在开发需要与IE 9及更高版本兼容的应用程序.我在一个MouseEvent对象上使用了MovementX属性,但是,此相同的MouseEvent对象在Internet Explorer(9或11)中不具有MovementX属性.
I am developing an application that needs to be compatible on IE 9 and above. I am using the movementX property on a MouseEvent object, however this same MouseEvent object does not have the movementX property in Internet Explorer (9 or 11).
我仔细阅读了Microsoft的文档,确实他们声称在其MouseEvent对象上支持此属性.我已经证实这实际上是一个MouseEvent对象,并且它根本没有该属性.除了该属性,其他所有属性似乎都可用.
I ran through Microsoft's documentation and indeed they claim to support this property on their MouseEvent objects. I have verified this is in fact a MouseEvent object, and it simply doesn't have the property. All the other properties appear to be available except this one.
有人有这个问题的经验吗?整个互联网对此似乎都保持沉默.
Does anyone have experience with this issue? The internet at large looks pretty silent on this one.
推荐答案
您将需要通过获取后续screenX
和screenY
值之间的增量来复制其行为.
You will need to replicate it's behaviour by taking the delta between subsequent screenX
and screenY
values.
// Store previous screenX/screenY somewhere outside of callback
var prevX = 0;
var prevY = 0;
// Callback whenever the mouse moves
function mousemove(e) {
var movementX = (prevX ? e.screenX - prevX : 0)
var movementY = (prevY ? e.screenY - prevY : 0)
prevX = e.screenX;
prevY = e.screenY;
}
请注意,如果您正在听mousemove
说话,弄清楚是否有东西被拖拽,则应在mouseup
上将prevX
和prevY
重置为0,否则将获得旧的屏幕值!
Note that if you are listening to mousemove
to say, figure out if something is being dragged, you should reset prevX
and prevY
to 0 on mouseup
or else you'll get the old screen values!
这篇关于Internet Explorer中显然不支持MouseEvent MovementX属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!