我在頁面上有一些隨機加載的圖像,它們超過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