【问题标题】:JavaScript image pre-loading not workingJavaScript图像预加载不起作用
【发布时间】:2014-05-08 08:08:44
【问题描述】:

我无法让这段代码为我工作。我想预先加载一些大图像,这些图像将在常规计时器上相互交换为当前页面的背景。

var images = new Array()
for (i = 1; i < 12; i++) {
    images[i] = new Image();
    images[i].src = "http://imagesource_" + i + ").jpg";
}

setInterval(function () {
    document.body.style.backgroundImage="url('" + images[11].src + "')";
}, 15000);

【问题讨论】:

  • 您确定src URL 正确吗?你得到什么样的错误?

标签: javascript image background preloading


【解决方案1】:

您现在没有预加载任何内容。你只是在一个数组中加载一堆 url。

看看:http://fragged.org/preloading-images-using-javascript-the-right-way-and-without-frameworks_744.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多