0

I tried to create canvas object with jQuery like this

this.canvas = $('<canvas/>', {
    id: this.id,
    width: this.width + 'px',
    height: this.height + 'px'
})[0];

it created a canvas with the right size, but when I tried to draw in it, every number I entered for Y-Coordinate was doubled, and the horizontal lines were thick and blurry. Everything was fine when I chnaged the above code to

this.canvas = document.createElement('canvas');
this.canvas.id = this.id;
this.canvas.width = this.width;
this.canvas.height = this.height;

It appears strange to me so I searched in Google but didn't find anything. May be someone here has bumped into a similar problem.

Thanks in advance!

  • jQuery sets the styles when you pass it `width` and `height`, while in the plain JS code you're setting the properties, and with canvas, there is a difference. – adeneo Sep 22 '16 at 23:28
  • @adeneo a better dupe : http://stackoverflow.com/questions/10433046/creating-a-canvas-element-and-setting-its-width-and-height-attributes-using-jque – Kaiido Sep 23 '16 at 05:23

0 Answers0