我需要改进一个 jquery 脚本,它将图像容器的高度捕捉到基线网格。我想让它在窗口调整大小期间工作。
到目前为止,我将以下内容应用于已将溢出设置为隐藏的图像容器。其中一些是受到此处和此处提出的问题的启发。
/* Updates height on $(window).load(function(){}); */
$(window).load(function(){
/* Adjust media container heights and image margins */
function containerHeight(){
var targetContainer = 'div.media';
$(targetContainer).each(function(){
var targetHeight = Math.round($(this).height() / 20) * 20 - 8;
if($(this).height() < targetHeight){
var newHeight = targetHeight - 20;
}else{
var newHeight = targetHeight;
}
$(this).css({
'height': newHeight
});
});
$(targetContainer).children('img').each(function(){
$(this).css({
'margin-top': Math.round(($(this).parent(targetContainer).height() - $(this).height()) / 2 )
});
});
}
containerHeight();
/* Does not update height on $(window).bind('resize', function(){}); with <body class="full"> */
$(window).bind('resize', function(){
containerHeight();
});
});
但是,我在http://pastie.org/2846491上的馅饼只适用于固定宽度的容器。
我需要为流体容器宽度/高度、窗口调整大小期间/之后和移动方向:纵向/横向更改,同时保持基线网格上的内容。
关于我应该如何处理这个问题的任何指示?请帮忙!