使用JavaScript预加载图像 [英] Preloading images with JavaScript
本文介绍了使用JavaScript预加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在下面编写的函数是否足以在当今大多数(如果不是全部)浏览器中预加载图像?
Is the function I wrote below enough to preload images in most, if not all, browsers commonly used today?
function preloadImage(url)
{
var img=new Image();
img.src=url;
}
我有一个图像URL数组,它们循环遍历并为每个URL调用preloadImage
函数.
I have an array of image URLs that I loop over and call the preloadImage
function for each URL.
推荐答案
是.这应该适用于所有主要的浏览器.
Yes. This should work on all major browsers.
这篇关于使用JavaScript预加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文