开发者

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

开发者 https://www.devze.com 2023-03-28 02:29 出处:网络
So I\'m attempting to load images in javascript dynamically as the user is scrolling around. The entire application is offline and 开发者_如何学Gois written in HTML and javascript. The \"scrolling\" a

So I'm attempting to load images in javascript dynamically as the user is scrolling around. The entire application is offline and 开发者_如何学Gois 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号