-2

我有以下引導模式...顯示此引導模態頁面加載

HTML:

<div id="tallModal" class="modal modal-wide fade"> 
    <div class="modal-dialog"> 
    <div class="modal-content"> 
     <div class="modal-header"> 
     <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> 
     <h4 class="modal-title">Modal title</h4> 
     </div> 
     <div class="modal-body"> 
     <p>One fine body&hellip;</p> 
     </div> 
     <div class="modal-footer"> 
     <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
     <button type="button" class="btn btn-primary">Save changes</button> 
     </div> 
    </div><!-- /.modal-content --> 
    </div><!-- /.modal-dialog --> 
</div><!-- /.modal --> 

CSS:

.modal.modal-wide .modal-dialog { 
    width: 90%; 
} 
.modal-wide .modal-body { 
    overflow-y: auto; 
} 

JS:

$(".modal-wide").on("show.bs.modal", function() { 
    var height = $(window).height() - 200; 
    $(this).find(".modal-body").css("max-height", height); 
}); 

這是在CodePen上:https://codepen.io/TomAshley/pen/wPxBjB

如何在頁面加載後立即顯示模式?我的這種嘗試是使用window.load,你可以在這裏看到:

$(window).load("show.bs.modal", function() { 
     var height = $(window).height() - 200; 
     $(this).find(".modal-body").css("max-height", height); 
    }); 

不過,這並不彈出模式。如何使它在頁面加載時彈出?

+0

我不認爲我應該使用id我的例子。這就是我問的原因。 – xendi

+0

它也可以和一個類一起工作,只是可能得到一個重複的 –

回答

3

觸發模態編程

$(document).ready(function() { 
    $('#tallModal').modal('show'); 
}); 

這裏是pen

+0

或者它可以是'$('。modal-wide')。modal('show');',對吧?謝謝 – xendi

+0

是的,你只改變了選擇器,但它匹配相同的元素,id(#)更安全 – ztadic91

+0

由於某些原因,在我的設計中,當我添加這個時,模式寬度要小得多。任何想法我怎麼能阻止呢? – xendi

0

對於這種情況,我們可以使用

$(document).ready(function() { 
    var height = $(window).height() - 200; 
    $(this).find(".modal-body").css("max-height", height); 
} 
+0

這不回答這個問題... –