간단한 캔버스 그리기, jsFiddle 좌표에 보인다 올바르게 인식되지 않는 :
JS :저 또는 jsfiddle 버그?
var w = $(".trace").width();
var h = $(".trace").height();
var bgCanvas = $("<canvas></canvas>").addClass("canvas");
bgCanvas.width(w).height(h);
var bgContext = bgCanvas[0].getContext("2d");
$(".trace").append(bgCanvas);
bgContext.strokeStyle = "#000";
bgContext.moveTo(0,0);
//this line should go to the middle of the canvas
//instead it goes much further both horizontally and vertically
bgContext.lineTo(200,100);
bgContext.stroke();
HTML :
<div class="trace"></div>
CSS :
.trace{
width: 400px;
height: 200px;
background: yellow;
}
.canvas{
border: 1px #000 dotted;
}
을
최신 IE 및 Chrome에서 확인되었습니다.
그들 (jsFiddle 개발자)은 github에서 문제를 제출하기 전에 다른 사람들과 공유하고 점검 할 것을 제안합니다. 그래서 ... 내 실수입니까, 아니면 jsFiddle입니까?
([캔버스는 "폭"/ "높이"속성 CSS를 사용하는 경우 연신 그러나 정상인] http://stackoverflow.com/questions/2588181/canvas-is-stretched-when- using-css-but-normal-with-width-height-properties), [canvas width attribute] (http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element)를 참조하십시오. .html # attr-canvas-width) – Andreas
끝내 주셔서 감사합니다! –