Skip to content

Instantly share code, notes, and snippets.

@jordanneenan
Created March 2, 2016 05:28
Show Gist options
  • Select an option

  • Save jordanneenan/5625d007c073aa4f4604 to your computer and use it in GitHub Desktop.

Select an option

Save jordanneenan/5625d007c073aa4f4604 to your computer and use it in GitHub Desktop.
Vertically align element to the middle of its parent
//vertically align element to the middle of its parent
function vAlign(){
if(jQuery('.v-align').length){
var jQueryvaChild = jQuery('.v-align');
jQueryvaChild.each(function(){
var vaChildHeight = jQuery(this).height();
var vaParentHeight = jQuery(this).parent().height();
var topOffset = (vaParentHeight - vaChildHeight) / 2;
jQuery(this).css('paddingTop', topOffset).addClass('show');
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment