Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there anyway to have jquery BlockUI vertically center on the screen

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 ?

like image 549
leora Avatar asked Feb 05 '12 02:02

leora


3 Answers

Here is the definite answer.

Create this function:

$.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ($(window).height() - this.height()) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}

After you call blockUI, center the dialog window like this:

$('.blockUI.blockMsg').center();
like image 155
oneiros Avatar answered Nov 11 '22 14:11

oneiros


Easily centered in the screen:

$.blockUI({
    message: myMessage,
    centerY: false,
    centerX: false,
    css:{
        position: 'fixed',
        margin: 'auto'
    }
});
like image 35
David Avatar answered Nov 11 '22 14:11

David


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.

centerX: true
centerY: true
like image 1
ShankarSangoli Avatar answered Nov 11 '22 16:11

ShankarSangoli