当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Why the picture doesn't draw on iPad2?

问题描述:

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);

});

})();

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: