Skip to content

Instantly share code, notes, and snippets.

@timstl
Created March 9, 2015 15:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timstl/c2dc5541094e99c72ee4 to your computer and use it in GitHub Desktop.
Save timstl/c2dc5541094e99c72ee4 to your computer and use it in GitHub Desktop.
jquery.vadjust.js
/*
vadjust plugin.
adjust top margin on vertically centered elements.
var $vadj = $('[data-vadjust="true"]');
if ($vadj.length > 0) { $vadj.vadjust(); }
*/
;(function($) {
$.fn.vadjust = function(options)
{
this.each(function() {
var $this = $(this),
mgn = (parseFloat($this.height()) / 2) * -1;
$this.css('margin-top', mgn + "px");
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment