Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

text-in-circles.js

By: a guest on Aug 11th, 2013  |  syntax: JavaScript  |  size: 0.78 KB  |  views: 293  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. jQuery(window).load(function(){
  2.         verticalCenterText( 'article', '.hometitle' );
  3. });
  4.  
  5. jQuery(window).resize(function(){
  6.         verticalCenterText( 'article', '.hometitle' );
  7. })
  8.  
  9. /** CENTER TEXT VERICALLY
  10.  * Center the text element vertically within its containing element
  11.  */
  12. function verticalCenterText( $containerEl, $textEl ) {
  13.  
  14.         $=jQuery;
  15.  
  16.         $( $containerEl ).each(function() {
  17.  
  18.                 if ( $(this).find( $textEl ).length > 0 ) {
  19.  
  20.                         var $containerElHeight = $(this).height();
  21.                         var $textElHeight  = $(this).find( $textEl ).height();
  22.  
  23.                         $(this).find( $textEl ).css('top', ( $containerElHeight - $textElHeight ) / 2 + 'px');
  24.  
  25.                 }
  26.  
  27.         });
  28.  
  29. }