简体   繁体   English

准备好文档还是在一定时间后运行?

[英]Document.ready or run after certain time?

i have preloader , which hides after document.ready . 我有预加载器,它隐藏在document.ready之后。

angular.element(document).ready(function () {
    var el =  document.getElementById('preloader');
    fadeOut(el);
});

Sometimes document loads so slowly , because of 1 or 2 big size photos , so i don't need to wait for this photos and need to hide preloader after 5000ms. 有时由于1或2张大尺寸照片,文件加载速度如此之慢,所以我不需要等待这张照片,也不需要在5000ms之后隐藏预加载器。

How can i do that ? 我怎样才能做到这一点 ? Thanks in advance . 提前致谢 。

That "document ready" process you're using is simply wrapping jQuery's (now deprecated) .ready() method. 您正在使用的“文档就绪”过程只是包装了jQuery(现已弃用) .ready()方法。 It does not wait for all images to load, it only waits for the DOM to be parsed. 不会等待所有图像加载,它只是等待要解析的DOM。 The window.onload event is the event that only fires after all images have loaded. window.onload事件是仅在加载所有图像后才触发的事件。

Instead, Angular has a directive called ng-cloak to prevent a "flash of unstyled content" (FOUC). 取而代之的是,Angular有一个名为ng-cloak的指令来防止“未样式化内容的闪烁”(FOUC)。 The cloak works by putting a class on a top level element, which you can then style to hide part, or all, of the page while you wait for a "ready" state. 披风的工作原理是将类放在顶层元素上,然后在等待“就绪”状态时可以对其进行样式设置以隐藏页面的一部分或全部。 You can use CSS transitions, rather than the jQuery .fadeOut() effect, to do a slow fade out on your preloader once the cloak is removed. 一旦删除了披风,您可以使用CSS过渡而不是jQuery .fadeOut()效果对预加载器进行缓慢的淡出。

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

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