开发者

Resizing the canvas with CSS skews up mouse action

So I have this fiddle which totally explains my issue.

Working fiddle

The JS

        var w = this.w * this.scale;
        var h = this.h * this.scale;
        var x = this.x - w * .5;
        var y = this.y - h * .5;

        //standard Canvas rotation operation
        ctx.save();
        ctx.translate(this.x, this.y);
        ctx.rotate(this.ro开发者_开发知识库tation * Math.PI / 180);

        ctx.fillStyle = this.fillStyle;
        ctx.fillRect(w * -0.5, h * -0.5, w, h);
        ctx.restore();

Defective fiddle


You can compare the size of the canvas to the CSS and make the necessary adjustments.

eg.

var cssScale = [canvas.getSize().x / canvas.get('width'),
                canvas.getSize().y / canvas.get('height')];
...
this.setDims(x*cssScale[0], y*cssScale[1], w*cssScale[0], h*cssScale[1]);
...
this.x = (x - this.offset[0]) / cssScale[0] + w * .5;
this.y = (y - this.offset[1]) / cssScale[1] + h * .5;

http://jsfiddle.net/rQkSF/


Not sure I understand the question but try resetting the size of the canvas height & width attributes to match the CSS when you resize.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜