html - CSS 图像消失得太快

标签 html css image delay

我有一个 gif 显示页面何时加载,但它不起作用。从我的 Angular 来看,我的代码似乎没问题。我曾多次尝试修改、添加、删除代码,但都没有用。我已经将 img src 添加到 div 加载器,但是预加载器只出现了几毫秒。一秒钟也没有。

#loader-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #fff;
    /* change if the mask should have another color then white */
    z-index: 9999;
    /* makes sure it stays on top */
}
#loader {
    width: 200px;
    height: 200px;
    position: absolute;
    left: 50%;
    /* centers the loading animation horizontally one the screen */
    top: 50%;
    /* centers the loading animation vertically one the screen */
    background-image: url("images/Preloader_1.gif");
    /* path to your loading animation */
    background-repeat: no-repeat;
    background-position: center;
    margin: -100px 0 0 -100px;
    /* is width and height divided by two */
}
<div id="loader-wrapper">
    <div id="loader"></div>
</div>

最佳答案

如果您希望在页面加载时加载 gif 动画,则需要使用 JavaScript。在下面的代码片段中,我提供了简单的 jQuery,它在页面加载时显示一个 gif,然后显示 HTML 的主体

jQuery(document).ready(function($) {

  $(window).load(function() {
    $('#loader').delay(500).fadeOut();
    $('#loader-wrapper').delay(500).fadeOut("slow");
  });

  $('body').show();

});
#loader-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #fff;
    /* change if the mask should have another color then white */
    z-index: 9999;
    /* makes sure it stays on top */
}
#loader {
    width: 200px;
    height: 200px;
    position: absolute;
    left: 50%;
    /* centers the loading animation horizontally one the screen */
    top: 50%;
    /* centers the loading animation vertically one the screen */
    background-image: url("http://img.ffffound.com/static-data/assets/6/77443320c6509d6b500e288695ee953502ecbd6d_m.gif");
    /* path to your loading animation */
    background-repeat: no-repeat;
    background-position: center;
    margin: -100px 0 0 -100px;
    /* is width and height divided by two */
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
  <div id="loader-wrapper">
    <div id="loader"></div>
</div>
  <p>hello</p>
</body>

关于html - CSS 图像消失得太快,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40201430/

相关文章:

html - 只对一张图片应用 css 样式

javascript - 您如何以编程方式检查 iframe 是否会被网站阻止?

html - 在 div 内拉伸(stretch)任意数量的跨度

html - 如何在不更改 html 的情况下更改 float div 顺序?

javascript - 在 Android 上使用 PhoneGap 进行地理定位仅适用于 index.html

html - SoundManager w HTML5 音频导致 206 部分内容错误?

html - Firefox anchor 大纲问题

android - 在 ListView 上捕捉 onFling

python - 如何移除移动物体以仅获取背景?

PHP/MYSQL 使用 while 循环获取当前行,然后从第 1 列输出数据,然后继续对后续行执行相同操作