canvas getContext(“2d”) returns null

前端 未结 5 2242
天命终不由人
天命终不由人 2020-12-05 17:53

I\'ve tried this a few different ways, but I keep getting stuck with the same error. I\'ve loaded an image to canvas before, but since I updated Safari a few days ago, I\'m

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-05 18:04

    For others who hit this page while searching for getContext returning null, it can happen if you have already requested a different type of context.

    For example:

    var canvas = ...;
    var ctx2d = canvas.getContext('2d');
    var ctx3d = canvas.getContext('webgl'); // will always be null
    

    The same is equally true if you reverse the order of calls.

提交回复
热议问题