I use bootstrap modal plugin. But modal dialog is not shown in center. Why? my mistake?
http://dl.dropbox.com/u/573972/stackoverflow/bootstrap/modal.html
Based on p4810's answer above but deal with where the user is on the screen too. Works with absolute positioning.
$('#YourModal').modal().css(
{
'margin-top': function () {
return window.pageYOffset-($(this).height() / 2 );
}
});
Did you try:
$( "#login" ).dialog({
modal: true
});
Ref: http://jqueryui.com//demos/dialog/modal.html
Capture the show
event of the .modal
and then calculate the new position:
$('body').on('show', '.modal', function(){
$(this).css({'margin-top':($(window).height()-$(this).height())/2,'top':'0'});
});
DEMO: http://jsfiddle.net/sonic1980/b2EHU/
if your twitter bootstrap modal dialog is not centered horizontally you can fix this via css.
just give the modal dialog a negative left margin that is half it's width like e.g. so:
.modalDialogBlabla {
margin: 0 0 0 -250px;
width: 500px;
}
I found this workarround to fix this issue:
$('#YourModal').modal().css(
{
'margin-top': function () {
return -($(this).height() / 2);
}
})
Source: https://github.com/twitter/bootstrap/issues/374