Vertically align


/ Published in: jQuery
Save to your folder(s)

usage: $('div img').vAlign();


Copy this code and paste it in your HTML
  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('margin-top', mh);
  9. });
  10. };
  11. })(jQuery);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.