javascript - 页面加载 jquery 之前的页面预加载器

标签 javascript jquery laravel loader

我对 jQuery 完全陌生。我试图在所有页面内容准备好之前显示加载程序。

<script>
$(document).ready(function(){
    $(document).ajaxStart(function(){
        console.log('wait');
        $("#wait").css("display", "block").show();
    });
    $(document).ajaxComplete(function(){
        $("#wait").css("display", "none").hide();
    });
});

在 body 里我有这个,

<div id="wait" style="display:none;position:absolute;top:20%;left:50%;"><img src="{{ asset('assets/global/img/ajax-loader.gif') }}" /></div>

但没有显示加载程序,并且控制台中没有显示错误。 谁能给我任何有关此问题的解决方案或示例?

提前致谢!

最佳答案

检查下面的演示代码。

$(document).ready(function(){
		$('#loader').fadeOut(showBodyPart);
		

		function showBodyPart(){
			$('#body_parts').fadeIn(300);
		}
	})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="loader">
     <img src="http://i.imgur.com/KUJoe.gif" id="a" alt="Loading" />
     Loading...
</div>

<div id="body_parts" style="display: none;">
	<p>If you click on me, I will disappear.</p>
	<p>Click me away!</p>
	<p>Click me too!</p>
</div>

关于javascript - 页面加载 jquery 之前的页面预加载器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50151637/

相关文章:

javascript - 如何使用嵌套对象中的参数过滤列表?

javascript - 在 ReduxReducer 中还是在组件的 ShouldComponentUpdate 中进行深度比较?

本地和生产的 Laravel 环境文件可能无法按预期工作?

Javascript 说我的类方法不是函数,尽管它显然是

javascript - 动态创建可滚动的 SVG

c# - 如何将 javascript 中的 JSON 数组传递到我的代码隐藏文件

javascript - jquery点击外部时隐藏div

javascript - 需要将稳定的 HTML 和 CSS 添加到 jquery "ContentFlow"

php - laravel 资源在获取数据时更改 id

php - 出现错误 Route not Define at LARAVEL