Created
March 2, 2016 05:28
-
-
Save jordanneenan/5625d007c073aa4f4604 to your computer and use it in GitHub Desktop.
Vertically align element to the middle of its parent
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
| //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