Skip to content

Instantly share code, notes, and snippets.

@pedrozath
Created October 31, 2012 22:03
Show Gist options
  • Select an option

  • Save pedrozath/3990232 to your computer and use it in GitHub Desktop.

Select an option

Save pedrozath/3990232 to your computer and use it in GitHub Desktop.
image discipliner
// ---------------------------------
// I M A G E D I S C I P L I N E R
// ---------------------------------
(function($){
$.fn.imageDiscipline = function(){
var obj = $(this);
var me = this;
var specified_width = 100;
var specified_height = 100;
obj.parent().height(specified_height);
obj.css("-webkit-transition", "all 300ms ease-out");
img = new Image();
img.setAttribute("src", obj.attr("src"));
img.onload = function(){
var width, height;
if(this.width > this.height){
obj.width(specified_width);
obj.css("margin-top", (specified_height - obj.height())/2 + "px");
} else {
obj.height(specified_height);
}
};
}
$(document).ready(function(){
$(".page-imprensa .logo img").each(function(){ $(this).imageDiscipline(); });
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment