Created
July 2, 2014 23:32
-
-
Save mikeselander/93fc49c292a62f78dd7e to your computer and use it in GitHub Desktop.
Maintain an exact size & margin between an unknown number of images within a parent div - useful for situations where a user can add multiple (unknown) number of logos to a box (generally footer)
This file contains hidden or 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
function adjust_header_banner(){ | |
var footer = $('.footer'); | |
count = 0; | |
totalWidth = 0; | |
// Calculate distance between partner images | |
$('.partners img').each(function() { | |
totalWidth += $(this).width(); | |
count += 1; | |
}); | |
var margin = ( ( footer.width() - totalWidth ) / ( count - 1 ) ) | |
$(".partners img").css({ | |
'margin-left' : ( margin / 2 ), | |
'margin-right' : ( margin / 2 ), | |
'max-width' : ( ( 100 / count ) - 1 ) + '%' | |
}); | |
} | |
$(document).ready(adjust_header_banner); | |
$(window).load(adjust_header_banner); | |
$(window).resize(adjust_header_banner); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment