我有一个名为#highlights的div,它交换文章标题和插图。当我使用jQuery切换到新的插图时,如下所示
$("#highlights").css("background","url("+path+")");第一次设置的背景图片显示得很慢。我该怎么解决这个问题呢?
发布于 2013-12-16 23:45:28
你可能想要preload the images (由James提供):
function preload(arrayOfImages) {
$(arrayOfImages).each(function(){
$('<img/>')[0].src = this;
// Alternatively you could use:
// (new Image()).src = this;
});
}
// Usage:
preload([
'img/imageName.jpg',
'img/anotherOne.jpg',
'img/blahblahblah.jpg'
]);https://stackoverflow.com/questions/20614830
复制相似问题