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