Preload images from an Ajax Call

前端 未结 2 511
太阳男子
太阳男子 2020-12-21 18:43

Could someone help me understand how to preload the images from random.php page so the first time it loads it fades in as it should. Currently its got an ugly bulk echo bec

2条回答
  •  梦毁少年i
    2020-12-21 19:04

    Here's a trick that I like: on a page before random.php add at the bottom of the page an img tag which references the image you want to fade in on random.php. Add to the img tag a CSS class which is simply display: none. This will prime the user's browser cache with the image so that when they do go to random.php the image was already downloaded and your fade works as expected. Of course this only works if random.php isn't the site landing page. Another factor is how many images you're talking about and their size.

提交回复
热议问题