Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raoulwegat/5500186 to your computer and use it in GitHub Desktop.
Save raoulwegat/5500186 to your computer and use it in GitHub Desktop.
Set parent height of absolutely positioned child
// set figure heights based on child image + figcaption heights
$(document).ready(function(){
setFigureHeight();
$(window).on('resize', setFigureHeight);
});
function setFigureHeight() {
$('.story-image').each(function(index,value) {
imgHeight = $(this).outerHeight(true);
capHeight = $(this).next('figcaption').outerHeight(true);
figHeight = imgHeight + capHeight;
// intro images at top get less height
if ( $(this).is('.intro') ) {
$(this).parent().css('height', figHeight);
} else {
// than images further down
$(this).parent().css('height', figHeight+48);
}
$(this).next('figcaption').css('top', imgHeight+8);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment