DOM上的BlockUI就绪 [英] BlockUI on DOM Ready

查看:86
本文介绍了DOM上的BlockUI就绪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery BlockUI插件向页面上添加加载内容由于CAML查询,加载需要花费几秒钟的时间.问题是,页面在之前加载,然后BlockUI短暂显示并消失.似乎JS执行顺序错误,我无法弄清楚原因.我可以在代码中进行某些更改吗?或者BlockUI只是不打算在没有Ajax的情况下使用?

I'm using the jQuery BlockUI plugin to add a loading splash to a page that takes a few seconds to load due to CAML queries. The problem is, the page loads before then the BlockUI displays for a split second and disappears. It seems like JS is executing these in the wrong order and I cannot figure out why. Is there something I can change in the code or is BlockUI just not intended to be used without Ajax?

$(document).ready(function() {
    $.blockUI();
});
$(window).ready(function() {
    $.unblockUI();
});

在html标头中,我调用jquery,blockui和common.js脚本,这些脚本包含CAML查询并按该顺序加载页面元素. common.js脚本也可以在DOM上运行,我怀疑这可能是问题的一部分...

In the html header I call jquery, blockui, and the common.js script that contain the CAML queries and load the page elements (in that order). The common.js script is also run on DOM ready, which I suspect may be part of the problem...

推荐答案

尝试一下:

<html>
    <head>
        <script src="jquery.js"></script>
        <script src="blockui.js"></script>
        <script type="text/javascript">
            $.blockUI();
        </script>
    </head>
    <body>
        …
    </body>
</html>

这应该在加载其他任何内容之前阻塞UI.

This should block the UI way before anything else has been loaded.

好的,我一直不愿意实际查找它…$.blockUI支持回调函数.

Okay, I've bothered to actually look it up … $.blockUI supports a callback function.

因此,您可以/应该这样做:

So, you could/should do this:

$(document).ready(function() {
    $.blockUI({
        onBlock: function() { 
            // Invoke your CAML stuff here.
        }
    });
});

这篇关于DOM上的BlockUI就绪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆