Puj*_*ava 8 html javascript css jquery html5-canvas
我在画布中使用背景图像.我想仅将背景图像旋转90度,但不应旋转上下文.如果我使用css变换然后整个画布旋转.我能怎么做 ?
var can = document.getElementById('canvas');
var ctx = can.getContext('2d');
ctx.rect(20, 30, 200, 40);
ctx.strokeStyle="red";
ctx.lineWidth="2";
ctx.stroke();
$(function(){
//$('#canvas').css({'transform':'rotate(90deg)'});
});Run Code Online (Sandbox Code Playgroud)
#canvas{
background: #789;
border: 1px solid;
}
body{
margin:10px;
}Run Code Online (Sandbox Code Playgroud)
<canvas id="canvas" width="400" height="300" style="background-image: url(http://placehold.it/1600x800); background-size: 100%; background-position: -80px -50px;">Your browser does not support HTML5 Canvas</canvas>Run Code Online (Sandbox Code Playgroud)