What is the best way to preload multiple images in JavaScript?

后端 未结 4 2049
一向
一向 2020-12-01 06:25

If I have an array of image filenames,

var preload = [\"a.gif\", \"b.gif\", \"c.gif\"];

and I want to preload them in a loop, is it necessa

4条回答
  •  借酒劲吻你
    2020-12-01 07:03

    EDIT:

    Actually, I just put it to the test, and Method A does not work as intended:

    Check it out: http://www.rootspot.com/stackoverflow/preload.php

    If you click on the 2nd image when the page is finished loading, it should appear instantaneously because it was preloaded, but the first one doesn't because it didn't have time to load before the source was changed. Interesting. With this new development, I'd just go ahead and use Method C.

提交回复
热议问题