我需要一些帮助。我不知道从哪里开始。我需要在我的网站上添加一个页面加载器。我首先提交一个表单,然后使用SimpleXML用expedia调用外部xml表。加载需要一分钟,所以我想将图像加载器添加到此页面。但是我该怎么做呢?我看过谷歌,找不到任何有用的信息。
我需要它来显示加载器,直到COMPLETE页面加载完毕。
答案 0 :(得分:14)
这有很多解决方案,但一个简单的方法是:
1-使用您的装载机东西创建一个叠加DIV并添加到BODY;
2-为隐藏此DIV的window.load
或document.ready
事件添加事件侦听器。
// On the first line inside BODY tag
<script type="text/javascript">
jQuery("body").prepend('<div id="preloader">Loading...</div>');
jQuery(document).ready(function() {
jQuery("#preloader").remove();
});
</script>
(已修复代码拼写错误)
答案 1 :(得分:3)
查看spin.js http://fgnass.github.com/spin.js/
var opts = {
lines: 13, // The number of lines to draw
length: 7, // The length of each line
width: 4, // The line thickness
radius: 10, // The radius of the inner circle
// Even more options available....
};
var target = document.getElementById('loading');
var spinner = new Spinner(opts).spin(target);
表格完成后:
$("#loading").data('spinner').stop();
答案 2 :(得分:2)
此加载器div将在页面加载时显示加载图像。
$(window).load(function() {
$(".pageloader").fadeOut("slow");
});
body {
background: black;/* for this demo */
}
.pageloader {
position: fixed;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
z-index: 9999;
background: url('images/yourLoaderImage.gif') 50% 50% no-repeat rgb(249, 249, 249);
opacity: .8;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<div class="pageloader"></div>
它完全为我工作。