我正在創建一個16:9比例響應div,但是當我調整窗口的大小時,container3
仍然保持原始大小,我的代碼中有任何問題?任何人都可以幫助我?由於創建響應div 16:9
$(document).ready(function(){
\t rp_config();
});
$(window).resize(function(){
\t rp_config();
});
function rp_config(){
\t var windowwidth = $(window).width();
\t var windowheight = $(window).height();
\t var bar = 64;
\t var bottom = 45;
\t var chat = 250;
\t var container2_width = windowwidth - chat;
\t var available_height = windowheight - bar - bottom;
\t
\t $(".container").width(windowwidth);
\t $(".container2").width(container2_width);
\t $(".container3").width(available_height/9 * 16);
\t
\t $(".container").height(available_height);
\t $(".container2").height(available_height);
\t $(".container3").height(available_height);
\t
\t
}
rp_config();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container" style="background-color:#000;">
\t <div class="container2" style="background-color:#333;">
\t <div class="container3" style="background-color:#ccc;">
</div>
</div>
</div>
我跑了你的片段,但看起來容器3相對地改變它的大小,你能進一步解釋它沒有改變,或者你做了什麼,你期望它是什麼,以及意外出現。 – fuyushimoya
爲什麼你使用JavaScript進行簡單的佈局任務? –
@fuyushimoya調整窗口寬度,容器3將變得更小,縱橫比16:9 –