FabricJS is not giving me movementX and movementY to pan a image in IE, however it works fine in other browsers

拜拜、爱过 提交于 2019-12-08 03:47:48

问题


I am loading a image in fabric.js and trying to add pan functionality to the image using this link . However, it works fine in Firefox, Chrome but doesn't work in IE(it just renders the image).

Here's the code :

var panImg = function () {
        var panning = false;
        canvas.on('mouse:up', function (e) {
            panning = false;
        });
        canvas.on('mouse:out', function (e) {
            panning = false;
        });
        canvas.on('mouse:down', function (e) {
            panning = true;
        });
        canvas.on('mouse:move', function(e) {
            if (panning && e && e.e) {
                console.log(e.e.movementX);
                var delta = new fabric.Point(e.e.movementX, e.e.movementY);
                canvas.relativePan(delta);
            }
        });
    }

If I debug ,what I see is e.e.movementX gives proper values in case of FF and Chrome but it gives undefined in case of IE. Is this a Fabric.js issue or am I missing something?


回答1:


Okay I got the answer with the help of @Infer-on Code :

canvas.on('mouse:move', function(e) {
            if (panning && e && e.e) {
                var x = e.e.movementX;
                var y = e.e.movementY;
                if(!x) {
                    x = e.e.screenX - previousEvent.e.screenX;
                    y = e.e.screenY - previousEvent.e.screenY;
                }
                var delta = new fabric.Point(x, y);
                canvas.relativePan(delta);
            }
            previousEvent = e;
        });


来源:https://stackoverflow.com/questions/40355425/fabricjs-is-not-giving-me-movementx-and-movementy-to-pan-a-image-in-ie-however

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