Grid drawn using a element looking stretched

后端 未结 2 1982
忘了有多久
忘了有多久 2020-12-30 04:02

I\'m trying to draw a grid on a element with the ultimate goal of making a Go board.

For some reason the grid is looking stretched, with

相关标签:
2条回答
  • 2020-12-30 04:28

    Please try it outside jsfiddle, maybe jsfiddle is applying some linear transformation.

    Also please make sure that you add 0.5 everywhere to both x and y coordinates. Alternatively, you can apply translate(0.5, 0.5) to shift all coordinates by half a pixel.

    0 讨论(0)
  • 2020-12-30 04:41

    I've found the problem. I was setting the dimensions of the <canvas> using CSS, when you actually have to set the width and height attributes. This was causing it to be stretched/skewed.

    var canvas = $('<canvas/>').attr({width: cw, height: ch}).appendTo('body');
    

    http://jsfiddle.net/h2yJn/66/

    alt text

    0 讨论(0)
提交回复
热议问题