阻止 UI 直到页面完全加载:jquery、blockUI 插件
当页面仍在加载时,如何使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
输出 body 标签后,您需要立即启动 blockUI 插件。
而不是传统的:
您需要忘记封闭的
$(function (){})
或$(document).ready(function (){})
所以你的脚本会立即触发:You'll need to fire the blockUI plugin as soon as the body tag is output.
Instead of the traditional:
You'll need to forget about the enclosing
$(function (){})
or$(document).ready(function (){})
so your script fires immediately:基于并纠正 Seb 的答案。 如果要阻止 UI,请使用 .blockUI();如果要定位对象,请使用 .block()。 我不认为您需要以 body 为目标,本质上这就是函数 blockUI 本身所做的事情。 您确实需要在 body 标记之后调用该函数...否则就没有
标记。 如果您确实希望在加载每个图像之前保持 UI 阻塞,请参阅最后一行。 如果您只想加载页面内容,您可以将解锁函数放在您熟悉的
$(document).ready(function().
的底部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().
您可以尝试在禁用所有组件的情况下启动页面,然后在 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.
问题在于引用 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.
你试过这个吗?
Have you tried this?
最终对我有用的完整代码如下:
The complete code that finally worked for me is the following: