Reputation: 3773
the following code works like a charm in Chrome, Safari and Firefox but doesn't work in my iPad2 iOS5 why
function preImage(url,callback){
var img = new Image();
img.src = url;
if (img.complete) {
callback.call(img);
return;
}
img.onload = function (){
callback.call(img);
};
}
(function() {
var my_canvas=document.getElementById("myCanvas");
var context=my_canvas.getContext("2d");
preImage("img/test.png",function(){
context.drawImage(this,0,0);
});
})();
Upvotes: 0
Views: 57
Reputation: 509
The following appears to work fine on my iPhone, and iPad simulator, both running IOS6. I notice you said IOS5, typo? or intended?
var preImage = function(url, callback){
var img = new Image();
img.src = url;
if (img.complete) {
callback.call(img);
return;
}
img.onload = function (){
callback.call(img);
};
};
(function() {
var my_canvas = document.getElementById("myCanvas");
var context = my_canvas.getContext("2d");
preImage("img/picture.jpg", function(){
context.drawImage(this,0,0);
});
})();
Notice the addition of the ';' after the preImage declaration.
Upvotes: 1