Created
October 31, 2012 22:03
-
-
Save pedrozath/3990232 to your computer and use it in GitHub Desktop.
image discipliner
This file contains hidden or 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
| // --------------------------------- | |
| // 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