gpt4 book ai didi

jquery - 将预加载器添加到一堆图像中

转载 作者:行者123 更新时间:2023-12-01 05:51:28 25 4
gpt4 key购买 nike

我正在使用一堆图像并创建幻灯片。

$(function(){
$("#big-image img:eq(0)").nextAll().hide();
$(".small-images img").click(function(e){
var index = $(this).index();
$("#big-image img").eq(index).show().siblings().hide();
});
});

我怎样才能:

如果有 20 张图像,则预加载图像以及如何在此过程中显示预加载图标?我看过一些关于 SO 的预加载示例,但似乎没有什么合适的。

一把 fiddle - http://jsfiddle.net/BkwrZ/

最佳答案

$.fn.preload = function (fn) {
var len = this.length, i = 0;
return this.each(function () {
var tmp = new Image, self = this;
if (fn) tmp.onload = function () {
fn.call(self, 100 * ++i / len, i === len);
};
tmp.src = this.src;
});
};

$('img').preload(function(perc, done) {
console.log(this, perc, done);
});

http://jsfiddle.net/yckart/ACbTK/

我给你的链接中有解释。只需阅读所有答案。 Preloading images with jQuery

因此,如果您想显示预加载的 perc,只需更改以下行:

console.log(this, perc, done);

所以不是将其记录在某些 div 中显示。

看这个例子 http://jsfiddle.net/ACbTK/6/

<小时/>

检查这个http://jsfiddle.net/BkwrZ/1/希望对您有帮助。

关于jquery - 将预加载器添加到一堆图像中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21807649/

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