【发布时间】:2015-02-13 08:03:11
【问题描述】:
我想加载以下 svg,它绝对位于屏幕中间,在 head 标签之前。 我有很多 css 和其他 javascript,我想先显示加载屏幕。
这可能吗?
CSS:
html body svg#circle-loader {
position: absolute; float: none; clear: both; top: 50%; right: 0; bottom: 0; left: 50%;
width: 50px; height: 50px; margin: -25px 0 0 -25px;
-webkit-animation: spin 1s linear infinite; -moz-animation: spin 1s linear infinite; animation: spin 1s linear infinite;
}
@-o-keyframes spin { 100% { -o-transform: rotate(360deg); } }
@-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
@-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
@keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } }
html body svg#circle-loader circle {
stroke-dasharray: 187; stroke-dashoffset: 50;
stroke: rgba(26, 60, 88, 0.9);
-webkit-transform-origin: center; -moz-transform-origin: center; -ms-transform-origin: center; transform-origin: center;
}
HTML:
<svg id="circle-loader" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 66 66" preserveAspectRatio="xMixYMid meet">
<circle class="path" fill="none" stroke-width="8" stroke-linecap="round" cx="33" cy="33" r="28"></circle>
</svg>
【问题讨论】:
-
为什么不创建另一个 div 来覆盖您的内容,方法是使用包含 SVG 的更高 z-index,然后在页面加载时关闭它?这应该在您的正文标签中,
body之外的对象会导致标记错误 -
@Alex 为了进入加载屏幕,它必须通过 head 标签。加载所有 CSS 和 javascript。然后才移动到 body 并加载 div。
-
有什么原因不能先加载css/js文件吗?
-
@Michael,那个和 js 需要一点时间来加载......
-
将您的动画放在
body的顶部,并将其必要的css 放在head中。将css包含在head中,js包含在body的底部。
标签: javascript jquery html css svg