[英]How do I remove the loading icon after the image is loaded?
I use lazy loading to load the images with the centered background loading icons, but I felt unnecessary to include the lazy loading effect in this question.我使用延迟加载来加载具有居中背景加载图标的图像,但我觉得没有必要在这个问题中包含延迟加载效果。 I want to remove the loading icon after the image is loaded because the smaller images may not cover the loading icon.
我想在加载图像后删除加载图标,因为较小的图像可能不会覆盖加载图标。
I use the same external CSS file for loading icons.我使用相同的外部 CSS 文件来加载图标。 None of the closest solutions worked for me.
最接近的解决方案都不适合我。
Any suggestions and help would be appreciated.任何建议和帮助将不胜感激。
HTML HTML
<div class="wrapper">
<img class="lazy" src="https://i.stack.imgur.com/kn7VW.jpg" alt="Large Image" width="800" height="380" />
</div>
<div class="wrapper">
<img class="lazy" src="https://i.stack.imgur.com/BsJCI.jpg" alt="Small Image" width="250" height="180" />
</div>
CSS CSS
.wrapper {
background: url(https://i.stack.imgur.com/yW2VY.gif) no-repeat center;
min-height: 220px;
}
You can implement onload
event of image, inside it remove class wrapper as您可以实现图像的
onload
事件,在其中将 class 包装器删除为
$(".lazy").on('load', function() { $('.wrapper').removeClass('wrapper'); })
Update: if you want to remove only loading for each image change to remove parent class only.更新:如果您只想删除每个图像更改的加载以仅删除父 class。
$(this).parent().removeClass('wrapper');
$(".lazy").on('load', function() { $(this).parent().removeClass('wrapper'); })
.wrapper { background: url(https://i.stack.imgur.com/yW2VY.gif) no-repeat center; min-height: 220px; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="wrapper"> <img class="lazy" src="https://i.stack.imgur.com/kn7VW.jpg" alt="Large Image" width="800" height="380" /> </div> <div class="wrapper"> <img class="lazy" src="https://i.stack.imgur.com/BsJCI.jpg" alt="Small Image" width="250" height="180" /> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.