有没有办法让 jquery BlockUI 在屏幕上垂直居中
我正在使用 jquery blockui 但所覆盖的 div 很长,因此会显示加载消息离开屏幕。
无论如何,是否有 jquery blockui 加载消息在可见屏幕上垂直居中,以便人们无需向下滚动即可看到消息?
I am using jquery blockui but the div that is being covered is very long, so the loading message shows up off the screen.
Is there anyway to have jquery blockui loading message vertically center on the visible screen so people can see the message without scrolling down ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这是明确的答案。
创建此函数:
调用 blockUI 后,将对话框窗口居中,如下所示:
Here is the definite answer.
Create this function:
After you call blockUI, center the dialog window like this:
轻松居中于屏幕:
Easily centered in the screen:
blockUI
默认情况下显示在屏幕中央。我相信即使您不断滚动页面它也会显示在中心。但是,您可以在调用
blockUI
时设置以下属性。blockUI
by default displays in the center of the screen. And I believe it displays in the center even when you keep scrolling the page.However you can set the below properties while calling
blockUI
.我使用 css 将 blockUI 居中。这适用于水平和垂直。
注意:您可能希望使用此
$.blockUI.defaults.css = {};
从 blockUI 中删除默认样式希望这有帮助。
I use css to center the blockUI. This works for both horizontal and vertical.
Note: you might want to remove default style from blockUI by using this
$.blockUI.defaults.css = {};
Hope this helps.
但你真的需要覆盖 div 吗?也许阻止整个页面是更好的选择?
这里有两种不同的方法:
1) 阻止整个页面
在这种情况下,您不需要任何附加功能,并且消息始终位于中心。
2) 阻止特定的 HTML 元素
但是,如果该元素的尺寸非常长,您就必须做一些额外的工作。首先声明方法
,然后声明
JS Fiddle 演示示例,在此处演示这两个选项
But do you really need to cover the div? Maybe the blocking the whole page is better option?
Here is two different approaches:
1) Block the whole page
In this case you do not need any additional functionality and the message always will be in center.
2) Block specific HTML element
But in case of the very long size of this element you have to do some extra work. First of all declare the method
and then
JS Fiddle demo example that demonstrate both options here
即使您调整窗口大小,这也会使消息居中:
无论如何,当您阻塞整个页面时,
centerX
和centerY
将不起作用,只会影响元素阻塞。This will center the message even if you resize the window:
Any how,
centerX
andcenterY
will not work when you are blocking the whole page, only effect element blocking.我为这个 jquery 插件编写了一个插件。
嗯,更要完善。
请注意如何获得高度中心。
I write a plugin for this jquery plugin.
Well more to perfect.
Please notice how to gain the center of height.