Skip to content

Instantly share code, notes, and snippets.

@craigmdennis
Created September 8, 2011 18:47
Show Gist options
  • Save craigmdennis/1204268 to your computer and use it in GitHub Desktop.
Save craigmdennis/1204268 to your computer and use it in GitHub Desktop.
Vertical Center jQuery Plugin
(function ($) {
$.fn.verticalCenter = function () {
var obj = this;
obj.parent().css({
'position': 'relative'
});
obj.css({
'margin-top': -this.outerHeight() / 2,
'margin-left': -this.outerWidth() / 2,
'position': 'absolute',
'top': '50%',
'left': '50%'
});
}
})(jQuery);
// Position the gallery vertically centered
$('.vertical-center').imagesLoaded(function () {
$(this).verticalCenter();
});
@craigmdennis
Copy link
Author

Now uses <href="https://github.com/desandro/imagesloaded">https://github.com/desandro/imagesloaded as cached images were causing a problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment