Last active
December 16, 2015 21:29
-
-
Save raoulwegat/5500186 to your computer and use it in GitHub Desktop.
Set parent height of absolutely positioned child
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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