阻止 UI 直到页面完全加载:jquery、blockUI 插件

发布于 2024-07-18 05:30:59 字数 139 浏览 8 评论 0原文

当页面仍在加载时,如何使用 jquery 和 blockUI 插件来阻止 UI? 如果使用 AJAX 调用加载页面,我知道解决方法,但是当页面通过回发加载时,如何阻止 ui 直到页面完全加载完毕?

请帮忙。 非常感谢您付出的努力和时间。

How can I block the UI when the page is still loading using jquery and blockUI plugin? If the page was being loaded using an AJAX call I know the workaround, but when the page is loading with a postback, then how to block the ui until the page has finished loading completely?

Please help. Many thanks in advance for your effort and time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

情未る 2024-07-25 05:30:59

输出 body 标签后,您需要立即启动 blockUI 插件。

而不是传统的:

<script type="text/javascript">
  $(function (){
    $("body").blockUI(options);
  });
</script>

您需要忘记封闭的 $(function (){})$(document).ready(function (){})所以你的脚本会立即触发:

<script type="text/javascript">
  $("body").blockUI(options);
</script>

You'll need to fire the blockUI plugin as soon as the body tag is output.

Instead of the traditional:

<script type="text/javascript">
  $(function (){
    $("body").blockUI(options);
  });
</script>

You'll need to forget about the enclosing $(function (){}) or $(document).ready(function (){}) so your script fires immediately:

<script type="text/javascript">
  $("body").blockUI(options);
</script>
素手挽清风 2024-07-25 05:30:59

基于并纠正 Seb 的答案。 如果要阻止 UI,请使用 .blockUI();如果要定位对象,请使用 .block()。 我不认为您需要以 body 为目标,本质上这就是函数 blockUI 本身所做的事情。 您确实需要在 body 标记之后调用该函数...否则就没有 标记。 如果您确实希望在加载每个图像之前保持 UI 阻塞,请参阅最后一行。 如果您只想加载页面内容,您可以将解锁函数放在您熟悉的 $(document).ready(function(). 的底部

<script type="text/javascript">  
$("body").block(options);   
//--or--  
$.blockUI(options);  
</script>

<script type="text/javascript">   
$(document).ready(function() {  
   $(window).load(function() { $.unblockUI(); }); //load everything including images.  
//--or--  
   $.unblockUI(); //only make sure the document is full loaded, including scripts.  
});  
</script>

Building on and correcting Seb's answer. If you are blocking the UI use .blockUI() and if targeting an object use .block(). I don't believe you need to target body, essentially that's what the function blockUI does on it's own. You DO need to call the function after the body tag... otherwise there is no <body> tag. If you really want to keep the UI blocked until every image is loaded, see the last line. If you only wanted the page content to load you could put the unblock function at the bottom of your familiar $(document).ready(function().

<script type="text/javascript">  
$("body").block(options);   
//--or--  
$.blockUI(options);  
</script>

<script type="text/javascript">   
$(document).ready(function() {  
   $(window).load(function() { $.unblockUI(); }); //load everything including images.  
//--or--  
   $.unblockUI(); //only make sure the document is full loaded, including scripts.  
});  
</script>
嘿嘿嘿 2024-07-25 05:30:59

您可以尝试在禁用所有组件的情况下启动页面,然后在 PageLoad 事件上启用它们。 另一个想法是放置一个隐藏所有页面的 CSS 类,并在使用 JQuery 加载时更改它。

You can try start the page with all components disabled and then enable their on the PageLoad event. Other idea is put a CSS class that hide all the page and change this on the load with JQuery.

成熟稳重的好男人 2024-07-25 05:30:59

问题在于引用 javascript 文件。

如果需要在 ASP.NET Ajax 页面中添加块 UI,请尝试在 ScriptManager 中包含 javascript 文件。

Problem would be in refering the javascript files.

If block UI needs to be added in the ASP.NET Ajax pages try including the javascript files in the ScriptManager.

〗斷ホ乔殘χμё〖 2024-07-25 05:30:59

你试过这个吗?

<script type="text/javascript">
    $(document).ready(function () {
        $.blockUI(options);
    });
</script>

Have you tried this?

<script type="text/javascript">
    $(document).ready(function () {
        $.blockUI(options);
    });
</script>
年华零落成诗 2024-07-25 05:30:59

最终对我有用的完整代码如下:

$("body").block({ message: '<h2>Loading...</h2>' });

$(document).ready(function () {
     $("body").unblock();
});

The complete code that finally worked for me is the following:

$("body").block({ message: '<h2>Loading...</h2>' });

$(document).ready(function () {
     $("body").unblock();
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文