简体   繁体   English

图像一旦预加载div,就加载了javascript文件?

[英]Preload div once images, javascript files are loaded?

I've been trying to work with jQuery libraries to preload content, the usual issue I ran into was that once all content is preloaded it displays a div however for a split seconds you can still see "bad looking" content as javascript wasn't applied to it yet, and than it changes to what it should look like. 我一直在尝试使用jQuery库来预加载内容,我遇到的常见问题是,一旦预加载了所有内容,它就会显示一个div,但是在一秒钟后,您仍然可以看到“外观不好”的内容,因为javascript不是应用于它,然后它更改为它的外观。 It's hard to explain. 很难解释。 Basically I'm trying to display div ( <div class="text"></div> ) on a page once whole page is loaded, so images, javascript files etc.. I found really good example of what I wan't over here 基本上,我试图在整个页面加载后在页面上显示div( <div class="text"></div> ),因此图像,javascript文件等也是如此。我发现了一个我不想要的很好的例子在这里

http://tympanus.net/codrops/collective/collective-58/ http://tympanus.net/codrops/collective/collective-58/

You can see that grid / content is only displayed once everything is loaded up, before that users get a loading image as indication to wait, that's exactly what I try to achieve. 您可以看到网格/内容仅在加载完所有内容后才显示,而在用户获得加载图像作为等待指示之前,这正是我试图实现的目标。 I tried looking at a source, but it seems that a "preload" script is somewhere within other scripts, and has lots of unnecessary code (for me). 我尝试查看源代码,但似乎“预加载”脚本位于其他脚本中,并且有很多不必要的代码(对我而言)。 so could you please suggest a lightweight jQuery solution for this issue? 所以您能为这个问题建议一个轻量级的jQuery解决方案吗?

For the div that is giving you trouble, why not set its visibility to "hidden" in the html and then in the javascript, after everything is ready, change it to "visible" 对于给您带来麻烦的div,为什么不在html和javascript中将其可见性设置为“隐藏”,则在一切准备就绪后,将其更改为“ visible”

html: HTML:

<div class="text" style="visibility:hidden"></div>

js: JS:

$(".text").css("visibility", "visible");

use display:none for your div initially and display a loading gif. 最初对您的div使用display:none并显示加载的gif。

$(window).load(function() { 
   $('#yourGifID').hide();
   $('#yourDivID').show(); // will be called when everything is loaded
});

The load event fires at the end of the document loading process. 加载事件在文档加载过程结束时触发。 At this point, all of the objects in the document are in the DOM, and all the images and sub-frames have finished loading. 此时,文档中的所有对象都在DOM中,并且所有图像和子帧均已完成加载。

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

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