简体   繁体   English

CSS动画在所有页面内容加载之前都是错误的

[英]CSS animations are buggy until all page content loads

I am working on a relatively ad heavy website that takes between 3 - 7 seconds to fully load (Depending on the number of ads on a page and the speed of the connection) and I want to add a CSS loading animation over the top of everything until the page has fully loaded. 我正在一个相对较重的广告网站上工作,该网站需要3到7秒的时间才能完全加载(取决于页面上的广告数量和连接速度),我想在所有内容的顶部添加CSS加载动画直到页面完全加载。

The only problem is, the animation is very glitchy UNTIL the page has fully loaded rendering it almost irrelevant. 唯一的问题是,除非页面已完全加载,否则动画非常不整洁,从而使其几乎不相关。

An example of what I mean (Not my site) is here http://smallenvelop.com/display-loading-icon-page-loads-completely/ the animations are all quite buggy until the page has loaded, at which time they start animating smoothly. 我的意思(不是我的网站)的示例在此处http://smallenvelop.com/display-loading-icon-page-loads-completely/直到页面加载完毕,动画才全部出现错误,此时它们开始动画流畅。

Is there any way to counter this? 有什么办法可以应对吗?

You could let jQuery wait until the page is loaded, fade out of wait x milliseconds. 您可以让jQuery等待直到页面加载完毕,然后逐渐消失,等待x毫秒。

Place this div into your html 将此div放入您的html中

<div class="loader"></div>

Then right at the last line of all your js: 然后就在所有js的最后一行:

$(window).load(function() {
    $(".loader").fadeOut(5000); 
});

In your css: 在您的CSS中:

.loader {
position: fixed;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
z-index: 9999;
background: url(../myloadinganimation.gif) center no-repeat #fff;

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

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