Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.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
Php JQuery预加载页面_Php_Jquery_Load - Fatal编程技术网

Php JQuery预加载页面

Php JQuery预加载页面,php,jquery,load,Php,Jquery,Load,我的问题很简单,我想在div中显示页面之前预装页面 我的索引页中有一个主div:#data_div 我将包含大量图像的页面加载到该分区中。。。(不仅是图像,还有大量标记) 我使用另一个div来预加载页面,该div不可见(但也不隐藏,以保持加载数据的良好格式):#数据_加载 我使用div加载符号:#wait_div 我想我需要与JQUERY load(事件,而不是load方法)等效的ajax 但我无法将此事件设置为div(…),因此我需要另一个解决方案 $.address.chan

我的问题很简单,我想在div中显示页面之前预装页面

我的索引页中有一个主div:#data_div

我将包含大量图像的页面加载到该分区中。。。(不仅是图像,还有大量标记)

我使用另一个div来预加载页面,该div不可见(但也不隐藏,以保持加载数据的良好格式):#数据_加载

我使用div加载符号:#wait_div

我想我需要与JQUERY load(事件,而不是load方法)等效的ajax 但我无法将此事件设置为div(…),因此我需要另一个解决方案

        $.address.change(function(event) {
                    $("#wait_div").show();

                    if(event.value == "/") {
                        $.address.value("index.php");
                    } else if(event.value.substr(1, 5) == "Datas") {
                        $("#data_loading").load(event.value, {
                            'ajax' : 'true'
                        },function(){

    /* i would like that this occur only when the page is fully loaded 
(including image and scripts) inside the temp div */
                           $("#data_div").children().remove();
                           $("#wait_div").hide();
                           $("#data_loading").children().appendTo($("#data_div")).fadeIn(1000);
                                //alert("done");
                            });
                        });
                    }
                });
我用(不是jQuery而是JavaScript)回答了这个问题:

注意:您可以在HTML中添加加载消息,并将其隐藏在preload()函数的末尾

JavaScript

function preload() {
    imageObj = new Image();
    images = new Array();
    images[0] = 'img/1.png';
    images[1] = 'img/2.png';
    images[2] = 'img/3.png';
    images[3] = 'img/4.png';
    images[4] = 'img/5.png';

    for (i = 0; i <= 4; i++)
        imageObj.src = images[i];
}
检查我问题的答案

这就是你如何知道当所有图像都被加载时,你可以给temp div中的图像一个类,并在你的新页面中执行如下操作:

  $(document).ready(function(){
    var imgs = $("img.tempDivImages"), cnt = imgs.length;

    imgs
    .load(function(){
      if(!--cnt) {
        /* all images loaded */
        /* now call the function you want when everything is loaded*/
      }
    })
    .error(function() { /* whoops an image failed to load */});
  });

这就是加载temp div中的所有内容时调用函数或执行某些操作的方式。

看看这个问题+答案[[1]:谢谢,但我不想加载单个图像,只需要在显示之前完全渲染我的div(也包括脚本)有帮助吗???提示它应该-也看看其余的答案,它们大多都提供了很好的建议。嘿,谢谢你的技巧,至少是图片感谢你的回答,但我不想单独加载图片,我只想在我的“页面”完全加载时引发一个事件…在临时分区。。。
#preload {
   position: absolute;
   overflow: hidden;
   left: -9999px; 
   top: -9999px;
   height: 1px;
   width: 1px;
}
  $(document).ready(function(){
    var imgs = $("img.tempDivImages"), cnt = imgs.length;

    imgs
    .load(function(){
      if(!--cnt) {
        /* all images loaded */
        /* now call the function you want when everything is loaded*/
      }
    })
    .error(function() { /* whoops an image failed to load */});
  });