Skip to content

Instantly share code, notes, and snippets.

@arielsalminen
Created May 8, 2012 09:50
Show Gist options
  • Save arielsalminen/2633926 to your computer and use it in GitHub Desktop.
Save arielsalminen/2633926 to your computer and use it in GitHub Desktop.
Center Images Vertically in JavaScript
jQuery(function () {
var imageHeight, wrapperHeight, overlap, imageContainer = $(".center_vertically");
function centerImagesVertically() {
imageHeight = imageContainer.find("img").height();
wrapperHeight = imageContainer.height();
overlap = (wrapperHeight - imageHeight) / 2;
imageContainer.find("img").css("margin-top", overlap);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment