javascript预加载图像数组保持请求图像
我有一个预加载函数,可以生成一个包含一些图像源的数组javascript预加载图像数组保持请求图像,javascript,Javascript,我有一个预加载函数,可以生成一个包含一些图像源的数组 function preload() { for (var n = 0; n < urls.length; n++) { images[n] = new Image; images[n].onload = updateCurrenttype(); images[n].src = urls[n]; console.log('urlsPreload[n]: '+urls[n]); }
function preload() {
for (var n = 0; n < urls.length; n++) {
images[n] = new Image;
images[n].onload = updateCurrenttype();
images[n].src = urls[n];
console.log('urlsPreload[n]: '+urls[n]);
}
}
function updateCurrenttype() {
currenttype = 1;
}
这些图像是一个动画,所以我不想一次又一次地下载这些图像,而是希望它们被重用
如何实现这一点有什么建议吗?你能同时发布
updateCurrenttype()
的正文吗?我认为这取决于你缓存服务器映像的配置。尝试将标题设置为caching@mohkhanupdateCurenttype()已发布。是否可以使用图像[n]数组而不是使用src属性<代码>图像项=图像[currentindex]代码>
function showimage() {
if (currenttype != 0) {
imageitem.src = images[currentindex].src;
}
console.log('urls[ci]:'+images[currentindex].src);
}