I need to improve a jquery script which snaps the height of image containers to a baseline grid. I want to make it work during window resize.
So far, I applied the following to the image containers which have overflow set to hidden. Some of it was inspired by questions asked here and here.
/* 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();
});
});
However, my pastie at http://pastie.org/2846491 only works for fixed-width containers.
I need to make this work for fluid container widths/heights, during/after window resize and mobile orientation:portrait/landscape changes, while keeping things on the baseline grid.
Any pointers on how I should approach this? Please help!