2017-06-19 16 views
0

以下のjqueryに相当するネイティブのjavascriptは何でしょうか?jQuery .attr(...)。load()に相当するネイティブJavaScript。

("<img/>").attr("src", "data:image/gif;base64," + base64).load(function() { 
    context.scale(width/this.width, height/this.height); 
    context.drawImage(this, 0, 0); 
    deferred.resolve($("<img/>").attr("src", canvas.toDataURL()));    
}); 
+0

[loadEvent(https://developer.mozilla.org/en-US/docs/Web/Events/load)および[のsetAttribute(HTTPS: //developer.mozilla.org/en/docs/Web/API/Element/setAttribute) – George

答えて

0

ようなもの:

var img = document.createElement('image'), 
    type = 'load',   
    callback = function() { 
     context.scale(width/this.width, height/this.height); 
     context.drawImage(this, 0, 0); 
     deferred.resolve(img.setAttribute('src', canvas.toDataURL())); 
    }; 

img.setAttribute('src', "data:image/gif;base64," + base64]); 
if (img.addEventListener) { 
    img.addEventListener(type, callback, false); 
} else if (img.attachEvent) { 
    img.attachEvent('on' + type, callback); 
} else { 
    img['on' + type] = callback; 
} 
// Add element into DOM 
document.body.appendChild(img); 
関連する問題