Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.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
Javascript 如何在head.js加载完脚本后加载一些页面内容_Javascript_Head.js - Fatal编程技术网

Javascript 如何在head.js加载完脚本后加载一些页面内容

Javascript 如何在head.js加载完脚本后加载一些页面内容,javascript,head.js,Javascript,Head.js,我目前正在使用head.js延迟加载我的网站的js文件。我在我的项目中使用colorbox。问题是,有时,colorbox没有完全加载,而是在新页面而不是对话框中打开colorbox,但当我进行多次刷新时,它最终会加载 我猜可能是在head.js完全加载colorbox js文件之前,就已经加载了用于打开colorbox对话框的页面内容。这是真正的原因吗 我希望每次都能正确显示颜色框,而无需刷新 如何使colorbox页面代码仅在head.js加载完所有依赖文件后执行 谢谢。nikk将您的配色箱

我目前正在使用head.js延迟加载我的网站的js文件。我在我的项目中使用colorbox。问题是,有时,colorbox没有完全加载,而是在新页面而不是对话框中打开colorbox,但当我进行多次刷新时,它最终会加载

我猜可能是在head.js完全加载colorbox js文件之前,就已经加载了用于打开colorbox对话框的页面内容。这是真正的原因吗

我希望每次都能正确显示颜色框,而无需刷新

如何使colorbox页面代码仅在head.js加载完所有依赖文件后执行


谢谢。nikk

将您的配色箱html代码放在一个div中

<div id="colorBoxDiv" style="display:none;">
</div>

head.js有很多不同的选项来实现这一点。您可以在加载所需文件时运行回调函数,或者使用测试功能api调用。 例如:

// queue scripts and fire a callback when loading is finished
head.load("file1.js", "file2.js", function() {
    // do something
 });

// same as above, but pass files in as an Array
head.load(["file1.js", "file2.js"], function() {
    // do something
});

// you can also give scripts a name (label)
head.load({ label1: "file1.js" }, { label2: "file2.js" }, function() {
    // do something
});

// same as above, but pass files in as an Array
head.load([{ label1: "file1.js" }, { label2: "file2.js" }], function() {
    // do something
});                   

// Labels are usually used in conjuntion with: head.ready()
head.ready("label1", function() {
    // do something
});

 // Actually if no label is supplied, internally the filename is used for the label
 head.ready("file1.js", function() {
    // do something
});
// queue scripts and fire a callback when loading is finished
head.load("file1.js", "file2.js", function() {
    // do something
 });

// same as above, but pass files in as an Array
head.load(["file1.js", "file2.js"], function() {
    // do something
});

// you can also give scripts a name (label)
head.load({ label1: "file1.js" }, { label2: "file2.js" }, function() {
    // do something
});

// same as above, but pass files in as an Array
head.load([{ label1: "file1.js" }, { label2: "file2.js" }], function() {
    // do something
});                   

// Labels are usually used in conjuntion with: head.ready()
head.ready("label1", function() {
    // do something
});

 // Actually if no label is supplied, internally the filename is used for the label
 head.ready("file1.js", function() {
    // do something
});