gpt4 book ai didi

javascript - 仅在完成加载后淡入图像

转载 作者:行者123 更新时间:2023-11-30 09:00:25 26 4
gpt4 key购买 nike

我在页面上随机加载了一些图像,它们超过 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);

最佳答案

应该可以,只需在您的样式表中将图像设置为 display:none 并修改将 src 设置为此的脚本位:

$(this).attr( { src: fullPath }).load(function() {
$(this).fadeIn()
});

关于javascript - 仅在完成加载后淡入图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9720050/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com