[英]globally trigger 'loading gif' while ALL images are loading (display inline)
Wondering what the best approach is to trigger a loading spinner gif before and while an image is loading. 想知道最好的方法是在加载图像之前和期间触发加载微调gif 。 .
。 I would like this small spinner gif to trigger **inline of where the image is loading ;
我希望这个小的微调gif可以触发**内联图像的加载位置 ; what is a good approach for this.. I do not want a spinner gif in the middle of the screen for every image , but inline where the image is loading.
这是什么好方法。 我不希望在屏幕中间为每个图像添加gif旋转框 ,而是在图像加载位置处内联。
Anyway to create one function for this to occur with all images across an application? 无论如何要创建一个功能来使应用程序中的所有图像都发生这种情况?
(Even better, but only a nice to have; could I detect .png
and then do it for all .pngs either answer would suffice. Either all images, or .pngs
only) (甚至更好,但只有一个不错的选择;我可以检测到
.png
,然后对所有.png
执行此操作,要么回答就足够。要么是所有图像,要么是.pngs
)。
Something along the lines of this logic: 遵循此逻辑的东西:
// if (not loaded?) * some condition that can detect
// code to be executed if condition is true
// show loading image
$('#loader_img').show();
// all images via img tag somehow?
$('img').on('load', function(){
// hide/remove the loading image
$('#loader_img').hide();
});
$('img').load(function() {
$('#loader_img').fadeOut();
});
//you can also check if there is an error whilst loading the image
$('img').error(function(){
$('#loader_img').fadeIn();
});
The loading image will disappear as soon as the image is loaded. 加载的图像将在加载后立即消失。 In Css it is even better, you can add a background loading.gif that will show and the loading image will just cover it up.
在Css中,它甚至更好,您可以添加将显示的背景loading.gif,而加载图像将覆盖它。
img {
background: url('loading-image.gif') no-repeat;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.