2015-03-30 55 views
2

我的網站有問題。我使用Bootstrap 3.2而不是模式。當對話框打開時,有一個滾動條,但關閉它會使滾動條消失。我讀過很多話題,但我還沒有找到工作解決方案。有什麼辦法可以解決這個問題嗎?關閉後,滾動條消失自舉對話框

所以,這是我的對話框代碼:

$("a.removeClass").click(function() { 

     var uid = $(this).attr('id'); 

     BootstrapDialog.show({ 
      message: 'Czy na pewno chcesz usunąć tą klasę?', 
      title: 'Usuwanie klasy', 
      buttons: [{ 
       label: 'Usuń klasę', 
       cssClass: 'btn-danger', 
       action: function(dialog) { 
        $(location).attr('href','index.php?app=admin&section=classes&uid=' + uid + '&remove'); 
       } 
      }] 
     }); 
    }); 

它也並不工作:How can I prevent body scrollbar and shifting when twitter bootstrap modal dialog is loaded?

+0

那麼......問題是什麼? – dowomenfart 2015-03-30 17:35:10

+0

歡迎來到SO。爲了讓人們更好地幫助你,你應該確保你的問題已經清楚地說明了。同時發佈相關代碼,讓社區知道您嘗試過的解決方案。 – crazymatt 2015-03-30 18:35:39

回答

0

添加到您的CSS:

.modal { 
    overflow-y: auto; 
} 
/* custom class to add space for scrollbar */ 
.modal-scrollbar { 
    margin-right: 15px; 
} 

這對您的JS:

(function($) { 

$(document) 
    .on('hidden.bs.modal', '.modal', function() { 
     $(document.body).removeClass('modal-scrollbar'); 
    }) 
    .on('show.bs.modal', '.modal', function() { 
     // Bootstrap's .modal-open class hides any scrollbar on the body, 
     // so if there IS a scrollbar on the body at modal open time, then 
     // add a right margin to take its place. 
     if ($(window).height() < $(document).height()) { 
      $(document.body).addClass('modal-scrollbar'); 
     } 
    }); 

})(window.jQuery); 

Via-How can I prevent body scrollbar and shifting when twitter bootstrap modal dialog is loaded?

+0

我已經試過了,沒有工作。 – kuba12300 2015-03-30 19:09:39