【发布时间】:2014-10-23 16:22:17
【问题描述】:
我在使用 jquery 为网站制作的背景轮播方面得到了帮助,它工作得很好.. 除了我发现页面最初可能需要一段时间才能加载.. 我想如果我真的下载了我的图片'正在使用背景而不是通过'http://www.whatever.jpg'加载它们,页面可能加载得更快..但我还是个菜鸟..并且无法弄清楚为什么这不是工作..这是我的代码:
var images = [
//even though I downloaded the picture and its in the same folder as this file.js, the background just loads a black page, then the other 2 load fine.
"bg1-orig.jpg",
"http://www.desktopaper.com/wp-content/uploads/Cool-Hd-Wallpapers-2.jpg",
"http://wallpaperscraft.com/image/restaurant_table_interior_modern_style_39288_1920x1080.jpg"
];
var $body = $("body"),
$bg = $("#bg"),
n = images.length,
c = 0; // Loop Counter
num = 200;
// Preload Array of images...
for(var i=0; i<n; i++){
var tImg = new Image();
tImg.src = images[i];
}
$body.css({backgroundImage : "url("+images[c]+")"});
(function loopBg(){
$bg.hide().css({backgroundImage : "url("+images[++c%n]+")"}).delay(7000).fadeTo(2200, 1, function(){
$body.css({backgroundImage : "url("+images[c%n]+")"});
loopBg();
});
}());
我已经搜索了一段时间...感谢您的帮助!
【问题讨论】:
-
没有“jquery 变量”之类的东西。语言是 JavaScript,jQuery 只是一个库,所以说 JavaScript 变量是正确的。
-
我想这也会对我没有托管网站这一事实产生巨大影响,因此这可能会导致它加载缓慢但我什至无法加载图片除非我使用 URL .. 但就像 lochermage 说的那样,无论如何它可能不会有什么不同..
标签: javascript jquery background