0
我正在调整图像使用画布和JavaScript ...图像完成后,我想要做一些逻辑。有没有完成的事件?我试图onloadend但它永远不会被调用:图像加载结束事件
var fr = new FileReader();
fr.onload = function (e) {
var img = new Image();
img.onloadend = function() {
console.log('finished logic here');
}
img.onload = function(){
var MAXWidthHeight = 488;
var ratio = MAXWidthHeight/Math.max(this.width,this.height);
var w = this.width * ratio;
var h = this.height * ratio;
var c = document.createElement("canvas");
c.width = w;
c.height = h;
c.getContext("2d").drawImage(this,0,0,w,h);
this.src = c.toDataURL();
document.body.appendChild(this);
}
img.src = e.target.result;
}
fr.readAsDataURL(files[i]);
onload是“onloadend”。一旦图像完全加载,它就会被触发。图像没有其他加载事件。 –
只需要在你的最后调整大小... – csanonymus
我在onload中放了几个日志语句......它们被多次触发 – thebiglebowski11