我在页面上有一些随机加载的图像,它们超过100kbs,是否可以让它完全加载然后淡入而不是逐步加载它?完成加载后淡入图像
我的JS是这样的......
(function($){
$.randomImage = {
defaults: {
//you can change these defaults to your own preferences.
path: '_images/', //change this to the path of your images
myImages: ['hero_eagle.jpg', 'hero_giraffe.jpg', 'hero_owl.jpg', 'hero_rabbit.jpg']
}
}
$.fn.extend({
randomImage:function(config) {
var config = $.extend({}, $.randomImage.defaults, config);
return this.each(function() {
var imageNames = config.myImages;
//get size of array, randomize a number from this
// use this number as the array index
var imageNamesSize = imageNames.length;
var lotteryNumber = Math.floor(Math.random()*imageNamesSize);
var winnerImage = imageNames[lotteryNumber];
var fullPath = config.path + winnerImage;
//put this image into DOM at class of randomImage
// alt tag will be image filename.
$(this).attr({ src: fullPath });
});
}
});
})(jQuery);
我是这么认为的,因为元素将被给予事件或某事之后是准备好了,如果你想显示加载用户可以通过放置元素后,你想要显示的是完整的,如果这是你可以使用的图像IMAGE.complete – viyancs 2012-03-15 12:57:53