简体   繁体   English

HTML5图片预加载

[英]HTML5 Image preloading

I am using the following: 我正在使用以下内容:

 window.addEventListener("load", pageFullyLoaded, false);

function pageFullyLoaded(e) {
// run animation instructions/function here
}

So the time all objects are in the DOM, images, scripts etc have finished loading my animation instructions can be fired. 因此,当所有对象都位于DOM中,图像,脚本等加载完毕时,可以触发我的动画指令。

My questions now is in regards to image preloading: In my CSS I have been using the following: 我现在的问题是关于图像预加载的:在CSS中,我一直在使用以下内容:

 body::after {
 content: url ("sprite.png");
 display: none;
 }

However, I am not really clear as to what the difference is in using or not using it, if the load event in the JS already waits on all the images to be available before the animation takes place? 但是,我不清楚使用或不使用它有什么区别,如果JS中的load事件已经在动画发生之前已经等待所有可用的图像了? Is there a benefit in using this in the CSS? 在CSS中使用它有好处吗?

The load event doesn't care about CSS. load事件与CSS无关。 They may or may not be loaded by the time the load event fires; 在加载事件触发时可能已加载,也可能未加载。 they may or may not be "lazy-loaded" only on request. 他们可能会或可能不会仅应要求“延迟加载”。

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

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