Skip to content

Instantly share code, notes, and snippets.

@victor-falcon
Created March 13, 2012 12:19
Show Gist options
  • Save victor-falcon/2028450 to your computer and use it in GitHub Desktop.
Save victor-falcon/2028450 to your computer and use it in GitHub Desktop.
Perfect Verticaly and Horizontaly aligment of Elements
<script type="text/javascript">
(function ($) {
$.fn.vAlign = function() {
return this.each(function(i){
var h = $(this).height();
var oh = $(this).parent().height();
var mt = (oh - h) / 2;
$(this).css("margin-top", mt + "px");
});
};
})(jQuery);
(function ($) {
$.fn.hAlign = function() {
return this.each(function(i){
var w = $(this).width();
var oh = $(this).parent().width();
var mt = (oh - h) / 2;
$(this).css("margin-left", mt + "px");
});
};
})(jQuery);
$(document).ready(function() {
$(".teaser-item .pos-media.media-left a img").vAlign();
$(".teaser-item .pos-media.media-left a img").hAlign();
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment