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 zazanik/57e693ecc9f6d7138c740ce9333fb051 to your computer and use it in GitHub Desktop.
Save zazanik/57e693ecc9f6d7138c740ce9333fb051 to your computer and use it in GitHub Desktop.
<div class="container test">
<img src="http://placehold.it/100x100" class="flex-item" alt="" />
<img src="http://placehold.it/100x100" class="flex-item" alt="" />
<img src="http://placehold.it/100x100" class="flex-item" alt="" />
</div>
$(window).load(function(){
/ Stuff to do after the page is loaded /
$conteinerWidth = $(".test").width();
$flexItem = $(".test .flex-item").length;
$totalItemWidth = 0;
$(".flex-item").each(function(index, el) {
$totalItemWidth += el.width;
});
$emptyWidth = $conteinerWidth - $totalItemWidth
$flexItem +=1
$margin = $emptyWidth / $flexItem;
$marginSUPER = $margin;
$margin /=2;
console.log($margin +" $margin");
$(".flex-item").css({"margin": $margin});
$(".flex-item").first().css({"marginLeft": $marginSUPER});
$(".flex-item").last().css({"marginRight": $marginSUPER});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment