canvas tag produces black block in chrome

℡╲_俬逩灬. 提交于 2020-01-15 01:19:33

问题


This is very frustrating. If I don't set the height and width of the canvas, canvas draws just fine, but when I do set the height and width I get back a black box. I've stripped my code down to an insane degree and can't find any problem. The canvas tag works great in FF and IE9.

var canvas = document.getElementById('can1');
var ctx = canvas.getContext('2d');   

canvas.width    = 280;  
canvas.height   = 270;

ctx.clearRect(0, 0, canvas.width, canvas.height);

Even just this destroys the canvas in google chrome. No matter how little I draw, if the height or width is set it fails. If I set the height or width with css instead, it produces a distorted result.

Any ideas?

UPDATE: I've discovered that if my canvas is small enough, it works in chrome. However I need a canvas that is 280x270 not 100x100


回答1:


Possible solution! For all animation use RequestAnimationFrame. Just worked on one of my projects!



来源:https://stackoverflow.com/questions/10439952/canvas-tag-produces-black-block-in-chrome

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