I got this lil file
/* 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;
}
and I use it like this
site=new waterContainer();
site.notifications[0]=new WBNotification(10,10,null,"hello there!");
site.notifications[0].draw()
everything works, but the this.draw() says(in chrome`s script reading thingy) that it cannot call method drawImage of null, how could I fix it?
You need to pass in the string "2d"
to getContext()
.
The function will return null
if the context-type supplied is not available.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.