zyra / ionic-image-loader

Ionic 2+ Component that loads images in a background thread and caches them for later use
MIT License
436 stars 137 forks source link

load event should only fire after the image's onload event has fired (6.3.2) #213

Open zakton5 opened 5 years ago

zakton5 commented 5 years ago

I am loading messages in a scrollable chat window and I want to make sure the chat is scrolled to the bottom immediately after the images have loaded. Currently the load event is fired before the img's onload event resulting in my chat window's scroll position being slightly higher than it should.

Here is my current workaround (I am using useImg):

const el = this.el.nativeElement as HTMLElement;
const image = el.getElementsByTagName('img')[0] as HTMLImageElement;
image.onload = () => {
    // Custom logic
};

I have to find the img tag in whatever component I am using and then manually wait for the onload event.