我正在尝试调整页面加载和窗口大小调整div的大小.下面放置代码</body>,它在页面加载时工作正常,但在窗口大小调整时没有任何作用.我使用警报测试了resize函数,该调整在调整大小时触发,但高度保持不变.
<script type='text/javascript'>
$('#main-content') .css({'height': (($(window).height()) - 361)+'px'});
$(window).resize(function(){
$('#main-content') .css({'height': (($(window).height()) - 361)+'px'});
alert('resized');
});
</script>
Run Code Online (Sandbox Code Playgroud)
更新:经过长时间休息后,我发现了导致问题的原因.我正在使用jquery脚本在正在调整大小的同一div上添加样式化滚动条.当我评论出来时,一切都很好.我已经在与调整大小相同的函数中移动了滚动条初始化,并尝试了我能想到的任何变化..仍然无法使其工作.
(#main-content div也有.scroll-pane类)
<script type='text/javascript'>
$(function(){
$('#main-content').css({'height':(($(window).height())-361)+'px'});
$('.scroll-pane').jScrollPane({scrollbarWidth:15, scrollbarMargin:15});
$(window).resize(function(){
$('#main-content').css({'height':(($(window).height())-361)+'px'});
});
});
</script>
Run Code Online (Sandbox Code Playgroud)