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