与下面的jquery等效的本机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 :(得分: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);