开发者

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

开发者 https://www.devze.com 2022-12-27 00:17 出处:网络
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:

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.get开发者_StackOverflow社区ElementsByTagName('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


Dug around and found this working solution;

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

works wonders!

0

精彩评论

暂无评论...
验证码 换一张
取 消