我现在正在使用以下函数将图像预加载到缓存中。我想知道是否有可能从内存中加载它们,以实现更快的加载时间。
function preloadImage (done, i) {
if (!i) { i = 1; }
var img = new Image();
img.onloadend = function () {
if (this.height == 0) { return done(); }
preloadImage(done, i + 1);
};
img.src = "images/" + i;
}
preloadImage(function () { console.log('images loaded'); });
我想做的是使用JavaScript加载图像()元素数组,然后在幻灯片中显示它们。