Modal plugin of Bootstrap 2 is not displayed by the center

后端 未结 5 621
没有蜡笔的小新
没有蜡笔的小新 2021-02-04 11:10

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



        
相关标签:
5条回答
  • 2021-02-04 11:52

    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 );
                    }
                });
    
    0 讨论(0)
  • 2021-02-04 11:53

    Did you try:

    $( "#login" ).dialog({
        modal: true
    });
    

    Ref: http://jqueryui.com//demos/dialog/modal.html

    0 讨论(0)
  • 2021-02-04 11:57

    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/

    0 讨论(0)
  • 2021-02-04 12:01

    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;
      }
    
    0 讨论(0)
  • 2021-02-04 12:15

    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

    0 讨论(0)
提交回复
热议问题