Flip< canvas> (旋转180deg) [英] Flip <canvas> (rotate 180deg) after being published on page
本文介绍了Flip< canvas> (旋转180deg)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试在将canvas元素附加到DOM后旋转它。
Canvas是600x50,这是手头的代码:
I'm trying to rotate a canvas element AFTER it's been appended to the DOM. Canvas is 600x50 and this is the code at hand:
var canvas = document.getElementsByTagName('canvas')[2];
var ctx = canvas.getContext('2d');
ctx.translate(300, 25); // rotate @ center
ctx.rotate(angle * Math.PI/180);
这不是完成任务。我错过了什么?
which isn't accomplishing the task. Am I missing something?
感谢
推荐答案
此工作解决方案;
context.scale(1,-1); //flip vertically
context.translate(0,-height); //move beneath original position
创造奇迹!
这篇关于Flip< canvas> (旋转180deg)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文