Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 隐藏所有内容,直到其完全加载_Jquery_Hide_Preloader - Fatal编程技术网

Jquery 隐藏所有内容,直到其完全加载

Jquery 隐藏所有内容,直到其完全加载,jquery,hide,preloader,Jquery,Hide,Preloader,这一小段基本代码显示了一个加载图标,该图标在加载文档时逐渐消失。正如您在这里看到的,在加载内容之前,它正在缓慢地显示内容 如何更改上述代码,使其在完全加载之前隐藏所有内容 整个页面 $(document).ready(function(){ setTimeout(function(){$('.preloader').fadeOut()}, 5000); }); 如果你也想等照片,那么 $(document).ready(function() { $('.preloader').fade

这一小段基本代码显示了一个加载图标,该图标在加载文档时逐渐消失。正如您在这里看到的,在加载内容之前,它正在缓慢地显示内容

如何更改上述代码,使其在完全加载之前隐藏所有内容

整个页面

$(document).ready(function(){
setTimeout(function(){$('.preloader').fadeOut()}, 5000);
});
如果你也想等照片,那么

$(document).ready(function() {
    $('.preloader').fadeOut(300);
});
$(文档).ready(函数(){
var imageCount=$('img')。长度;
$('img').load(函数(){
图像计数--;

如果(imageCount document ready)是在DOM就绪后触发的,而不是在加载所有内容后触发的。
$(窗口)。on('load',handler)
似乎您正在查找的内容如果缓存了任何图像,则此操作将不起作用,因为onload处理程序将不会运行。如果我只希望它隐藏页面上的图像,而不隐藏其余内容,那么如何实现此操作呢?这是一个单独的问题,在本网站上已多次询问和回答。请确保使用
$(document).ready(function() {

    var imageCount = $('img').length;
    $('img').load(function() {
        imageCount--;
        if (imageCount <= 0)
            $('.preloader').fadeOut(300);
    });

});
$(document).on('ready', function () {
  // this is run first, as soon as we can play with the DOM
  showLoadingScreen();
});

$(window).on('load', function () {
  // this is run after, once all the content has loaded (img etc)
  hideLoadingScreen();
});