【发布时间】:2015-03-11 17:22:21
【问题描述】:
我的网站包含相当多的广告,这些广告需要一段时间才能加载。这完全不是问题,但我注意到任何 SVG 动画都会立即绘制第一帧,但动画只有在页面上的所有加载完成后才会出现。 SVG 动画通常表示一个微调器/加载图标。 有没有一种方法可以立即启动 SVG 动画? 或者如果我将它转换为纯 CSS,它会立即动画吗?
这是我的 svg 加载器代码: http://jsfiddle.net/5zq5j4d9/
<div class="loading-icon-outer">
<div class="loading-icon">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="20px" height="20px" viewBox="0 0 20 20" style="enable-background:new 0 0 50 50;" xml:space="preserve">
<rect x="0" y="8" width="4" height="4" fill="#333" opacity="0.2">
<animate attributeName="opacity" attributeType="XML" values="0.2; 1; 0.2" begin="0s" dur="0.6s" repeatCount="indefinite" />
<animate attributeName="height" attributeType="XML" values="4; 20; 4" begin="0s" dur="0.6s" repeatCount="indefinite" />
<animate attributeName="y" attributeType="XML" values="8; 0; 8" begin="0s" dur="0.6s" repeatCount="indefinite" />
</rect>
<rect x="8" y="8" width="4" height="4" fill="#333" opacity="0.2">
<animate attributeName="opacity" attributeType="XML" values="0.2; 1; 0.2" begin="0.15s" dur="0.6s" repeatCount="indefinite" />
<animate attributeName="height" attributeType="XML" values="4; 20; 4" begin="0.15s" dur="0.6s" repeatCount="indefinite" />
<animate attributeName="y" attributeType="XML" values="8; 0; 8" begin="0.15s" dur="0.6s" repeatCount="indefinite" />
</rect>
<rect x="16" y="8" width="4" height="4" fill="#333" opacity="0.2">
<animate attributeName="opacity" attributeType="XML" values="0.2; 1; 0.2" begin="0.3s" dur="0.6s" repeatCount="indefinite" />
<animate attributeName="height" attributeType="XML" values="4; 20; 4" begin="0.3s" dur="0.6s" repeatCount="indefinite" />
<animate attributeName="y" attributeType="XML" values="8; 0; 8" begin="0.3s" dur="0.6s" repeatCount="indefinite" />
</rect>
</svg>
</div>
</div>
【问题讨论】:
-
codePen 上有一个和你类似的例子……使用 AnimateTransform 加载……codepen.io/aurer/pen/jEGbA
-
这就是我得到加载器图标的地方。 AnimateTransform 与我使用的不同吗?它会在加载页面时立即播放动画吗?
-
不确定...我对您的代码没有任何问题,但由于有些人想要结束这个问题,所以不敢说。它可能在加载的时间,因为你有很多事情要做。这个 HTML 是从一个单独的文件中加载的,还是在它应该运行的主 HTML 文件中加载的?是否在正文部分的末尾加载了广告调用?