【发布时间】:2014-07-30 18:44:11
【问题描述】:
我有一个 gif,在我的网站加载时出现,但是 gif 消散器和页面在所有内容加载后出现,除了通过 css 调用的背景图像。
我怎么能让 gif 只有在背景图像加载后才消失。
我正在为加载程序使用此代码:
html:
<html class="loading">
<!-- All the things -->
</html>
css:
html {
-webkit-transition: background-color 1s;
transition: background-color 1s;
}
html, body {
/* For the loading indicator to be vertically centered ensure */
/* the html and body elements take up the full viewport */
min-height: 100%;
}
html.loading {
/* Replace #333 with the background-color of your choice */
/* Replace loading.gif with the loading image of your choice */
background: #333 url('loading.gif') no-repeat 50% 50%;
/* Ensures that the transition only runs in one direction */
-webkit-transition: background-color 0;
transition: background-color 0;
}
body {
-webkit-transition: opacity 1s ease-in;
transition: opacity 1s ease-in;
}
html.loading body {
/* Make the contents of the body opaque during loading */
opacity: 0;
/* Ensures that the transition only runs in one direction */
-webkit-transition: opacity 0;
transition: opacity 0;
}
javascript
// IE10+
document.getElementsByTagName( "html" )[0].classList.remove( "loading" );
// All browsers
document.getElementsByTagName( "html" )[0].className.replace( /loading/, "" );
// Or with jQuery
$( "html" ).removeClass( "loading" );
谢谢
【问题讨论】:
-
css中的背景在哪里定义?
-
像这样:
#homepage { background: url(/wp-content/uploads/2014/07/home.jpg) fixed; background-repeat:no-repeat; -webkit-background-size:cover; -moz-background-size:cover; -o-background-size:cover; background-size:cover; background-position: bottom; overflow: auto; margin: 0 auto; width: 100%; position: relative; padding: 0 0 0 0; height: 100vh; } -
你的控制台说什么?是否显示任何错误?这可能只是错误的路径。
-
是否有工作示例或页面的实时视图?
-
一种方法是使用
window.onload或jquery 的$(window).load,当页面上的所有内容都加载完毕时会触发。
标签: javascript jquery html css loader