我得到了这个 lil 文件
/* WaterBall API notification model by Makerimages*/
function WBNotification(x,y,icon,text)
{
this.background="/WBGraphics/WBNotification.png";
this.x=x;
this.y=y;
this.icon=icon;
this.text=text;
this.draw=function()
{
var canvas = document.createElement('canvas');
canvas.id="WBNotificationArea";
canvas.width=88;
canvas.height =43;
document.body.appendChild(canvas);
cvs=document.getElementById("WBNotificationArea");
var context=cvs.getContext();
context.drawImage(this.background,this.x,this.y);
}
return this;
}
我这样使用它
site=new waterContainer();
site.notifications[0]=new WBNotification(10,10,null,"hello there!");
site.notifications[0].draw()
一切正常,但是 this.draw() 说(在 chrome 的脚本读取 thingy 中)它无法调用 null 的方法drawImage,我该如何修复它?
最佳答案
您需要将字符串"2d"
传递给getContext()
。
如果提供的上下文类型不可用,该函数将返回null
。
关于javascript - JS无法调用null的drawImage方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19321022/