backbone.bootstrap-modal icon indicating copy to clipboard operation
backbone.bootstrap-modal copied to clipboard

Adding a new option to automatically center modal

Open nathanpeck opened this issue 10 years ago • 3 comments

Adds a new option called "center", which if true will automatically center the modal on first display, and recenter it nicely if the window resizes. Destroys the resizing binding nicely when removing the view.

nathanpeck avatar Feb 26 '14 07:02 nathanpeck

I tried to apply your code on my project, and it only center it when resize the window. At first load the following code returns margin-top and margin-left equals 0.

      $el.find('.modal-dialog').css({
        'margin-top': function () {
          return -($(this).outerHeight() / 2);
        },
        'margin-left': function () {
          return -($(this).outerWidth() / 2);
        }
      });

rafaelfaria avatar Mar 22 '14 08:03 rafaelfaria

Are you using Bootstrap 3? And which browser were you using? If you can give me a minimum page that demonstrates the issue I'll see if I can fix it. In the meantime I haven't experienced any issues with the automatic centering of any of my views.

nathanpeck avatar Mar 22 '14 18:03 nathanpeck

Yeah. Bootstrap 3. Backbone JS 1.1.0. Chrome 33.

If i trigger resize after the page has loaded, the modal window snap to the center.

I'm trying to debug as well, but it might be something related to time it is trying to compute the width and height. If i find anything i post it in here too.

rafaelfaria avatar Mar 23 '14 03:03 rafaelfaria