简体   繁体   English

图像加载后如何删除加载图标?

[英]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.

相关问题 使用Ajax将图像拖入div中,如何在调用前为div添加高度,然后在加载图像后将其移除? - Using Ajax to pull image into div, how do I add height to div before call, then remove it after image is loaded? 当我的标记加载到传单地图时,我如何添加加载图标/加载器? - How do i add a loading icon/ loader while my markers get loaded into the leaflet map? 如何删除加载图标extjs 4? - how I remove loading icon extjs 4? 动画 svg 加载图标直到图像加载 - animated svg loading icon until image loaded React-JS 如何在加载图片库之前显示预加载器图标? - React-JS How do I make a preloader icon appear before the image gallery is loaded? 加载图像后删除 class - Remove a class after image is loaded 窗口本身已加载后,如何触发加载事件? - How do I trigger a loading event after the window itself has been loaded? 循环后如何删除/隐藏图像? - How do I remove/hide the image after the loop? 用户单击“提交”按钮后,如何使图像或图标出现在另一图像上? - After a user hits the submit button, how do I make an image or icon appear over another image? 如果在加载延迟加载图像后图像被破坏,则设置图像默认值。 我怎么做的? - set image default if image is broken after lazy load image loading . how i do this?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM