简体   繁体   English

将iFrame CSS设置为在加载期间显示:none

[英]Setting iFrame CSS to display:none during load

I have this: 我有这个:

<div class="upload_slide">
    <iframe class="upload_iframe" style="visibility:hidden;"></iframe>
</div>

If I then post some files to the iFrame and set .upload_slide to display:none; 如果我然后将一些文件发布到iFrame并将.upload_slide设置为display:none; , while it's loading, will this affect the loading of the iFrame or the detection of when it finished loading? ,当它正在加载时,这是否会影响iFrame的加载或检测何时完成加载?

There shouldn't be a problem but if there is, a good trick can be to move the element offscreen rather than hiding it. 应该没有问题,但如果有,一个好的技巧可以是将元素移出屏幕而不是隐藏它。 You can create a class like 你可以创建一个类

.offscreen{
    position: absolute;
    left: -5000px;
}

which you can add and remove as needed. 您可以根据需要添加和删除。

Firefox currently does have an issue with display:none: Firefox目前确实存在display:none的问题:

Some browsers assume that when "display:none" is applied to replaced elements (like Flash or an iframe) the visual info for that element is no longer needed. 某些浏览器假设当“display:none”应用于替换元素(如Flash或iframe)时,不再需要该元素的可视信息。 So, if the element is later displayed by the CSS, the browser will actually recreate the visual data form scratch. 因此,如果稍后由CSS显示该元素,则浏览器实际上将重新创建可视数据表单。

I imagine that having the iframe default to "display:none;" 我想iframe默认为“display:none;” makes the browser skip the rendering of the HTML so the tags don't have any dimensions. 使浏览器跳过HTML的呈现,使标签没有任何尺寸。 I would set the visibility to "hidden" or position it off the page rather than use "display:none;". 我将可见性设置为“隐藏”或将其置于页面之外,而不是使用“display:none;”。

Steven Paligo 史蒂文帕利戈

Link 链接

No, the iFrame's loading and load detection should not be compromised by setting the display to none. 不,通过将显示设置为无,不应损害iFrame的加载和负载检测。

CSS is just for style, it has no ability to affect the DOM. CSS仅用于样式,它无法影响DOM。

Nope.. Not at all.. 没有..完全没有..

CSS - display:none or visibility:hidden only says the browser to not to show the iframe content to user. CSS - display:nonevisibility:hidden仅表示浏览器不向用户显示iframe内容。

But the functionality will work fine without any issues. 但功能将正常工作,没有任何问题。

As far as I am aware, it should work fine. 据我所知,它应该工作正常。 I've been using hidden iframes to load stuff for a while and haven't had any issues. 我一直在使用隐藏的iframe加载一段时间的东西,并没有任何问题。

That said I know that some browsers try to be efficient by not loading images that are hidden, so it's possible that some browsers (particularly mobile ones) do the same with iframes. 这就是说我知道有些浏览器试图通过不加载隐藏的图像来提高效率,因此有些浏览器(尤其是移动浏览器)可能会对iframe执行相同操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM