[英]Div height relative to another div on window resize
我下面的函數可以在初始加載時正確加載,並設置div高度以匹配視頻的高度。 但是,當我調整窗口大小時, #top-content
元素會降低其高度。
jQuery(window).resize(function () {
var vidHeight = jQuery('video').height();
jQuery('#top-content').css({
'height': vidHeight + 'px'
});
var vidPicHeight = jQuery('.video-element').height();
jQuery('#top-content').css({
'height': vidPicHeight + 'px'
});
console.log(vidHeight);
}).trigger('resize');
我有一個正在運行的控制台日志,變量vidHeight
隨着窗口大小的變化而改變,只是不更新樣式。
嘗試這個
var vidHeight = jQuery('video').height();
jQuery('#top-content').css('height', vidHeight);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.