【发布时间】:2010-09-26 19:04:16
【问题描述】:
如何从底部中心角度旋转带有 canvas html5 元素的图像?
<html>
<head>
<title>test</title>
<script type="text/javascript">
function startup() {
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var img = new Image();
img.src = 'player.gif';
img.onload = function() {
ctx.translate(185, 185);
ctx.rotate(90 * Math.PI / 180);
ctx.drawImage(img, 0, 0, 64, 120);
}
}
</script>
</head>
<body onload='startup();'>
<canvas id="canvas" style="position: absolute; left: 300px; top: 300px;" width="800" height="800"></canvas>
</body>
</html>
不幸的是,这似乎从图像的左上角旋转它。有什么想法吗?
编辑:最终物体(宇宙飞船)必须像时钟指针一样旋转,好像它在向右/向左转。
【问题讨论】:
-
code.google.com/p/explorercanvas 它将为您添加出色的跨浏览器支持,这不是一回事,因为对于 IE,您实际上将使用 VML
标签: javascript html canvas rotation