想知道为什么这不起作用...
功能:
$.fn.preload = function() {
this.each(function(){
$('<img/>')[0].src = this;
});
}
代码:
<?php $preimages = glob('images/backgrounds/*{.jpg, .png, .gif, jpeg}', GLOB_BRACE); ?>
$([
<?php
$imgcount = sizeof($preimages);
for($i = 0; $i < $imgcount; $i++) {
if($i == $imgcount-1)
echo $preimages[$i];
else
echo $preimages[$i] . ', ';
}
?>
]).preload($("#load").fadeOut());
我正在尝试预加载 foler images/backgrounds 文件夹中的所有图像...但是我希望回调为 $("#load").fadeOut()...
但是,当我这样做时,它会起作用,如下所示:
img1 = new Image();
img2 = new Image();
img3 = new Image();
img1loaded = false;
img2loaded = false;
img3loaded = false;
img1.onload = function() {
img1loaded = true;
if(img1loaded && img2loaded && img3loaded) {
$("#load").fadeOut();
}
};
img2.onload = function() {
img2loaded = true;
if(img1loaded && img2loaded && img3loaded) {
$("#load").fadeOut();
}
};
img3.onload = function() {
img3loaded = true;
if(img1loaded && img2loaded && img3loaded) {
$("#load").fadeOut();
}
};
img1.src = '<?php echo $baseUrl; ?>images/backgrounds/img1.jpg';
img2.src = '<?php echo $baseUrl; ?>images/backgrounds/img2.jpg';
img3.src = '<?php echo $baseUrl; ?>images/backgrounds/img3.jpg';
我怎样才能做我上面做的事情,但动态?
谢谢!