我需要根據iframe
內容的高度來調整此模式的bootstrap
大小,因爲它是動態的。Bootstrap Modal - 基於iframe高度調整大小的模式
使用onload
和下面的函數我什麼也沒有。除非你把它明確地使用height
屬性(你不這樣做),一個默認爲150像素的高度 http://plnkr.co/edit/eElqXJwvxmpc1XMrdwIK?p=preview
我需要根據iframe
內容的高度來調整此模式的bootstrap
大小,因爲它是動態的。Bootstrap Modal - 基於iframe高度調整大小的模式
使用onload
和下面的函數我什麼也沒有。除非你把它明確地使用height
屬性(你不這樣做),一個默認爲150像素的高度 http://plnkr.co/edit/eElqXJwvxmpc1XMrdwIK?p=preview
:
window.resizeIframe = function() {
var frame = $('#custom-frame');
var modalHeight = $('#custom-frame').contents().height();
frame.height(modalHeight);
$(window).resize(function() {
frame.height(modalHeight);
});
};
我提供了一個plunker。在設置模態高度之前,您需要設置高度。一些信息在this question。
使用本:
<div class="media video-container">
<iframe width="640" height="390" src="https://www.youtube.com/embed/OqP54KZOz0U" frameborder="0" allowfullscreen></iframe>
</div>
和CSS是:
.video-container {
position: relative;
padding-bottom: 56.25%;
padding-top: 30px;
height: 0;
overflow: hidden;}
.video-container iframe, .video-container object, .video-container embed {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;}
你能詳細解釋一下嗎?爲什麼你將.video-container高度設置爲56.25%? – captainrad
鏈接說,普拉克無法找到。 –
不,這很好。再試一次.. – captainrad
_Sigh._我不會騙你。如果我是你,我只會使用JSFiddle。 –