我的网站是一个单页网站,其中5个DIV充当面板(类名为.panel),适合拉伸浏览器窗口的整个高度和宽度。我的下面的代码已经做到这一点,但是,我的内容可以大于.panel /浏览器窗口的高度。目前这个内容被隐藏了。即.panel DIV实际上是窗口的高度,没有别的。如果其中的内容大于浏览器窗口的高度,我需要扩展它。
如何编辑以下代码以添加此功能?也许为这个调整后的DIV添加一个类名,以便我可以相应地设置它的样式?
// In my plugins.js file
function fitElements(){
var height=$(window).height();
var width=$(window).width();
$('.panel').css('height',height);
$('.panel').css('width',width)
};
// At the bottom of my HTML file (to call the function)
jQuery(document).ready(function($) {
fitElements();
});
// My current code also adjusts on browser resize - so would need this answer to do the same
$(window).resize(fitElements);
答案 0 :(得分:1)
更改部分
$('.panel').css('height',height);
到
if (height > $('.panel').height) {
$('.panel').css('height',height);
}
用于重新调整大小的函数add
$('.panel').css('height','auto');
进入函数的开头