Posted By

xz on 04/28/11


Tagged

center vertical


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

AllKnightAccess
maltem
wirenaught


vertical centering with jQuery


 / Published in: jQuery
 

  1. (function ($) {
  2. // VERTICALLY ALIGN FUNCTION
  3. $.fn.vAlign = function() {
  4. return this.each(function(i){
  5. var ah = $(this).height();
  6. var ph = $(this).parent().height();
  7. var mh = (ph - ah) / 2;
  8. $(this).css('padding-top', mh);
  9. });
  10. };
  11.  
  12. })(jQuery);
  13.  
  14. $('.centered').vAlign();

Report this snippet  

You need to login to post a comment.