Created
September 8, 2011 18:47
-
-
Save craigmdennis/1204268 to your computer and use it in GitHub Desktop.
Vertical Center jQuery Plugin
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 ($) { | |
$.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(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now uses <href="https://github.com/desandro/imagesloaded">https://github.com/desandro/imagesloaded as cached images were causing a problem