在页面加载时显示图像

Display image while page onLoad

本文关键字:显示 显示图 图像 加载      更新时间:2023-09-26

在我的HTML页面中,我使用某些选项加载,处理,在页面中加载外部.txt文件 因为此过程需要一些时间来加载我需要显示图像,直到过程结束

我找到了这个脚本

<script>
      // Put an animated GIF image insight of content
      $("#content").empty().html('<img src="http://www.website.com/images/loading.gif" />');
      // Make AJAX call
      $("#content").load("http://website.com/page.php")
      </script>

因为我使用许多进程,如页面加载处理加载 txt 文件

那么如何在上述提及过程中降低页面透明度和显示图像(.gif)

这是一个有效的 CSS 吹泡加载微调器。您甚至不需要上传任何其他内容。只需简单地定位要显示微调器的字段即可。并在必要时使用.show().hide()显示和隐藏微调器。

参考

  $('.loader').show(); //show
  $("#content").load("http://website.com/page.php") {
    $('.loader').delay(1000).hide(); //hide
  }
.loader:before,
.loader:after,
.loader {
  display: none;
  border-radius: 50%;
  width: 2.5em;
  height: 2.5em;
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
  -webkit-animation: load7 1.8s infinite ease-in-out;
  animation: load7 1.8s infinite ease-in-out;
}
.loader {
  margin: 8em auto;
  font-size: 10px;
  position: relative;
  text-indent: -9999em;
  -webkit-animation-delay: 0.16s;
  animation-delay: 0.16s;
}
.loader:before {
  left: -3.5em;
}
.loader:after {
  left: 3.5em;
  -webkit-animation-delay: 0.32s;
  animation-delay: 0.32s;
}
.loader:before,
.loader:after {
  content: '';
  position: absolute;
  top: 0;
}
@-webkit-keyframes load7 {
  0%, 80%, 100% {
    box-shadow: 0 2.5em 0 -1.3em #ffffff;
  }
  40% {
    box-shadow: 0 2.5em 0 0 #FFF;
  }
}
@keyframes load7 {
  0%, 80%, 100% {
    box-shadow: 0 2.5em 0 -1.3em #ffffff;
  }
  40% {
    box-shadow: 0 2.5em 0 0 #FFF;
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="loader">Loading...</div>

更新:

另一种方法是:

  • 添加 html 元素,您将在其中显示加载器。(例如 #example)
  • display: hidden添加到#example
  • 在要加载或加载之前,将.show()添加到#example
  • 阿贾克斯调用
  • 调用请求后.hide() #example