我正在寻找一种使用JavaScript预加载图像的快捷方法.我正在使用jQuery,如果这很重要的话.
我在这里看到了这个(http://nettuts.com ...):
function complexLoad(config, fileNames) {
for (var x = 0; x < fileNames.length; x++) {
$("<img>").attr({
id: fileNames[x],
src: config.imgDir + fileNames[x] + config.imgFormat,
title: "The " + fileNames[x] + " nebula"
}).appendTo("#" + config.imgContainer).css({ display: "none" });
}
};
Run Code Online (Sandbox Code Playgroud)
但是,它看起来有点过头了我想要的东西!
我知道有jQuery插件可以做到这一点,但它们看起来都有点大(大小); 我只需要快速,简单和简短的预加载图像方式!
在我的网站上是一个固定的图像.该图像应该是"动画的",这意味着应该迭代动画的单个帧.因此,我们的想法是拥有一个图像数组,每次用户滚动时,都会迭代数组,并且显示的图像会发生变化,从而创建动画.我不习惯使用JS,因此我真的不知道从哪里开始.我唯一拥有的是CSS:
#animation {
background-repeat: no-repeat;
position : fixed;
width: 980px;
margin: 0 auto;
}
Run Code Online (Sandbox Code Playgroud)