Created
March 13, 2012 12:19
-
-
Save victor-falcon/2028450 to your computer and use it in GitHub Desktop.
Perfect Verticaly and Horizontaly aligment of Elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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