Javascript 页面预加载程序加载延迟
我使用一个自定义CSS预加载程序,它是通过以下jQuery代码段加载的 问题是它与javascript一起加载,因此需要一段时间。结果是,在最初的2-3秒内,我的页面上没有任何内容,也没有预加载程序 我尝试在项目中向上移动我的预加载程序脚本,以在开始加载它,但这没有多大帮助 如何使其立即加载且无延迟Javascript 页面预加载程序加载延迟,javascript,jquery,html,css,preloader,Javascript,Jquery,Html,Css,Preloader,我使用一个自定义CSS预加载程序,它是通过以下jQuery代码段加载的 问题是它与javascript一起加载,因此需要一段时间。结果是,在最初的2-3秒内,我的页面上没有任何内容,也没有预加载程序 我尝试在项目中向上移动我的预加载程序脚本,以在开始加载它,但这没有多大帮助 如何使其立即加载且无延迟 <!-- Preloader --> <script type="text/javascript"> //<![CDATA[ $
<!-- Preloader -->
<script type="text/javascript">
//<![CDATA[
$(window).load(function () { // makes sure the whole site is loaded
$('#status').load("preloader/preloader.html"); // will first fade out the loading animation
$('#preloader').delay(2500).fadeOut('slow'); // will fade out the white DIV that covers the website.
$('body').delay(2500).css({
'overflow': 'visible'
});
})
//]]>
</script>
//
preload.html是我的css预加载程序的html代码。延迟时间过长的原因是您正在等待加载整个站点。这通常由图像占据,因此将
$(窗口)替换为$(文档)。用$(文档)加载。ready
可能会加快加载速度。还要注意您的延迟为2500毫秒(2.5秒),减少延迟也会使加载速度加快
<!-- Preloader -->
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() { // makes sure the whole site is loaded
$('#status').load("preloader/preloader.html", function() {
//run after ajax get request completes (preloader.html is loaded)
//now we remove the delays since we have explicity waited for the preloader to load
$('#preloader').fadeOut('slow'); // will fade out the white DIV that covers the website.
$('body').css({
'overflow': 'visible'
});
});
});
//]]>
</script>
//
延迟时间过长的原因是您正在等待整个站点加载。这通常由图像占据,因此将$(窗口)替换为$(文档)。用$(文档)加载。ready
可能会加快加载速度。还要注意您的延迟为2500毫秒(2.5秒),减少延迟也会使加载速度加快
<!-- Preloader -->
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() { // makes sure the whole site is loaded
$('#status').load("preloader/preloader.html", function() {
//run after ajax get request completes (preloader.html is loaded)
//now we remove the delays since we have explicity waited for the preloader to load
$('#preloader').fadeOut('slow'); // will fade out the white DIV that covers the website.
$('body').css({
'overflow': 'visible'
});
});
});
//]]>
</script>
//
此脚本在HTML中的位置?此脚本在HTML中的位置?