Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load images dynamically without blocking UI in Javascript on mobile application?

So I'm attempting to load images in javascript dynamically as the user is scrolling around. The entire application is offline and is written in HTML and javascript. The "scrolling" around behavior is done through CSS3 animations.

The problem is that when I set image.src = "foo.png" it blocks the UI until the image has loaded. Is there a way around this?

like image 727
DevDevDev Avatar asked Sep 27 '26 04:09

DevDevDev


1 Answers

How long is the UI being blocked? If it is local then I wouldn't have thought it much at all.

Anyhow, the reason the UI may be being blocked is because it needs to download the image to determine its size. If it doesn't know the image size it will not know how it will affect the layout.

The first think I would do is to set with and height attributes as soon as the tag is created.

like image 114
martin Avatar answered Sep 29 '26 18:09

martin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!