powmedia / backbone.bootstrap-modal

Bootstrap Modal wrapper for use with Backbone.
MIT License
183 stars 97 forks source link

Adding a new option to automatically center modal #61

Open nathanpeck opened 10 years ago

nathanpeck commented 10 years ago

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.

rafaelfaria commented 10 years ago

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);
        }
      });
nathanpeck commented 10 years ago

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.

rafaelfaria commented 10 years ago

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.