javascript - 在 iframe 加载时隐藏加载器

标签 javascript jquery html css iframe

我需要在 iframe 加载时隐藏加载程序,并在它再次加载时显示

<div id="loader" class="holds-the-iframe"><iframe id="frame" src="http://www.test.com" frameborder="0" ></iframe></div>


<style>
.holds-the-iframe {
  background:url(https://i.giphy.com/media/3oEjI6SIIHBdRxXI40/giphy.webp) center center no-repeat;
}

</style>

解决这个问题的最佳方法是什么?我知道它可以用 jquery 制作,但我更喜欢纯 javascript 解决方案。

最佳答案

试试这段代码..我没有放图片..我只是用word..你可以把它改成图片.

HTML

<iframe src="https://www.test.com/" id="foo"></iframe>
<div id="loadingMessage">Loading...</div>

CSS

#loadingMessage {
    width: 100%;
    height: 100%;
    z-index: 1000;
    background: #ccc;
    top: 0px;
    left; 0px;
    position: absolute;
}

Javascript

$('#foo').ready(function () {
    $('#loadingMessage').css('display', 'none');
});
$('#foo').load(function () {
    $('#loadingMessage').css('display', 'none');
});

希望能帮到你。

关于javascript - 在 iframe 加载时隐藏加载器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57601553/

相关文章:

javascript - 输入在空输入上返回 true

html - 如何通过调整窗口大小将图像固定在右下角?

javascript - Alfresco:根据文档的位置添加标签

javascript - 如何使用内联 JavaScript 或 CSS 隐藏 TD 标签?

javascript - Bootstrap-选择 : Unable to create a simple select box using bootstrap-select?

html - 我的 main.css 没有链接到我电脑的 html 文件 "outside"

html - float 元素变成居中元素

javascript - react native : How to split a file up into multiple files and import them?

javascript - 无法将消息从 Chrome 扩展中的 popup.js 发送到 background.js

Jquery日期选择器图标隐藏