代码之家  ›  专栏  ›  技术社区  ›  Shouvik

使用CSS向上倾斜鼠标操作调整画布大小

  •  3
  • Shouvik  · 技术社区  · 14 年前

    所以我有一把小提琴完全解释了我的问题。

    Working fiddle

            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.rotation * Math.PI / 180);
    
            ctx.fillStyle = this.fillStyle;
            ctx.fillRect(w * -0.5, h * -0.5, w, h);
            ctx.restore();
    

    Defective fiddle

    2 回复  |  直到 10 年前
        1
  •  1
  •   iRyanBell    14 年前

    您可以将画布的大小与CSS进行比较,并进行必要的调整。

    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/

        2
  •  0
  •   Stephen Stephen    14 年前

    我不确定我是否理解这个问题,但请尝试在调整大小时重置画布高度和宽度属性的大小,以匹配CSS。

    推荐文章