英文:
event.movementX is not working in IE11 if i use mousemove event inside mousedown event
问题
在以下代码中,我试图传递鼠标坐标以进行列调整大小。在Chrome中可以正常工作,但在IE11中无法正常工作,因为IE11中event.movementX始终为未定义。有人能提供解决方案吗:
private mouseDown(): void {
document.addEventListener("mouseup", this.mouseUp);
document.addEventListener("mousemove", this.mouseMove, true);
}
private mouseMove(event: MouseEvent): void {
if (this.props.resizing) {
this.props.resizing(this.props.index, event.movementX);
}
}
英文:
In the following code I am trying to pass the mouse coordinates for column resizing. It is working in chrome, but not in IE11, event.movementX is always undefined in IE11, can anyone suggest the solution for this:
private mouseDown(): void {
document.addEventListener("mouseup", this.mouseUp);
document.addEventListener("mousemove", this.mouseMove, true);
}
private mouseMove(event: MouseEvent): void {
if (this.props.resizing) {
this.props.resizing(this.props.index, event.movementX);
}
}
答案1
得分: 0
如MouseEvent.movementX在IE11中不受支持,您需要以以下旧方式处理它:
<html>
<body>
<p id="log">移动鼠标。</p>
</body>
<script>
function logMovement(event) {
if(event.movementX){
// 在Chrome 79中有效
log.insertAdjacentHTML('afterbegin', '移动: ' + event.movementX + ', ' + event.movementY + '<br>');
}else{
// 在IE11中有效
log.insertAdjacentHTML('afterbegin', '屏幕: ' + event.screenX + ',' + event.screenY + '<br>');
}
}
const log = document.getElementById('log');
document.addEventListener('mousemove', logMovement);
</script>
</html>
此代码示例已在IE11和Chrome 79上进行了测试,您可以在jsbin上尝试它:https://jsbin.com/kexuzuc/edit。还请注意,像${var}
这样的语法元素以及许多其他功能在IE11中不受支持。
英文:
As MouseEvent.movementX is not supported by IE11 you need to handle it in an old fashion way like in the following:
<html>
<body>
<p id="log">Move your mouse around.</p>
</body>
<script>
function logMovement(event) {
if(event.movementX){
//works with Chrome 79
log.insertAdjacentHTML('afterbegin', 'movement: ${event.movementX}, ${event.movementY}<br>');
}else{
//works with IE11
log.insertAdjacentHTML('afterbegin', 'screen: ' + event.screenX +',' + event.screenY + '<br>');
}
}
const log = document.getElementById('log');
document.addEventListener('mousemove', logMovement);
</script>
</html>
This code sample was tested on IE11 and Chrome 79 you can play with it in jsbin here: https://jsbin.com/kexuzuc/edit. Also note that syntaxic element like ${var} and many other feature are not supported by IE11.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论