Flip <canvas> (rotate 180deg) after being published on page

谁说我不能喝 提交于 2020-01-15 10:45:09

问题


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?

Thanks


回答1:


Dug around and found this working solution;

context.scale(1,-1); //flip vertically 
context.translate(0,-height); //move beneath original position

works wonders!



来源:https://stackoverflow.com/questions/2634456/flip-canvas-rotate-180deg-after-being-published-on-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!