I am working on my 1st website using bootstrap. I'm using javascript to center my images vertically, however what I noticed that sometimes javascript is loaded before some of the images, so those images aren't centered.
Html:
<div class="hidden-xs col-sm-3 text-center">
<img src="../img/body/gear.png" alt="gear.png" class="scale-icon pull-center" />
</div>
JavaScript:
<script>
function pullCenter() {
$(this).css('margin-top', $(this).parent().parent().height()/2-$(this).height()/2);
}
$('.pull-center').each(pullCenter);
$( window ).resize(function() {
$('.pull-center').each(pullCenter);
});
</script>
How can I make sure that all images are already loaded before executing
$('.pull-center').each(pullCenter);
Java script is at the bottom of html.