0

I have a HTML5 Canvas object, which I resize using Javascript. I then draw on it.

On iOS, the drawing doesn't show unless I delay the drawing with setTimeout.

So this code shows nothing...

myCanvas.width = width;
myContext.strokeStyle = '#000';
myContext.moveTo(0, 0);
myContext.lineTo(2000, 2000);
myContext.stroke();

...but this does:

myCanvas.width = width;

setTimeout(function(){
    myContext.strokeStyle = '#000';
    myContext.moveTo(0, 0);
    myContext.lineTo(2000, 2000);
    myContext.stroke();
}, 100);

Both work fine on desktop browsers, but not in Safari iOS.

What's causing this and is setTimeout the best solution to get around it?

Thanks,

Fijjit
  • 1,399
  • 2
  • 17
  • 31

1 Answers1

0

My mistake. Turns out the setTimeout had nothing to do with it.

What I did discover though that might help others is that there is a maximum size allowed for canvasses in the browsers and this is surprisingly small on mobile browsers (e.g. Safari).

See this question for more info: Maximum size of a <canvas> element

I was trying to render a canvas too large for iPhone.

Community
  • 1
  • 1
Fijjit
  • 1,399
  • 2
  • 17
  • 31