Created
March 29, 2010 23:59
-
-
Save joshmvandercom/348575 to your computer and use it in GitHub Desktop.
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
$(document).ready(function(){ | |
$('.js_resize').each(function(){ | |
var imageParent = $(this).parent(); | |
var myWidth = $(this).width(); | |
var myHeight = $(this).height(); | |
var parentWidth = $(this).parent().width(); | |
var parentHeight = $(this).parent().height(); | |
var offset, ratio, newSide; | |
if (myWidth>myHeight) { | |
if ($(this).height()>parentHeight) { | |
var ratio = parentHeight / $(this).height(); | |
} else { | |
var ratio = $(this).height() / parentHeight; | |
} | |
newSide = ratio * $(this).width(); | |
$(this).height(parentHeight); | |
if (newSide>parentWidth) { | |
$(this).css({'margin-left': parseInt((newSide - parentWidth)) * -1}); | |
} else { | |
$(this).css({'margin-left': parseInt((parentWidth - newSide)) * -1}); | |
} | |
} else if (myWidth<myHeight) { | |
if ($(this).width()>parentWidth) { | |
var ratio = parentWidth / $(this).width(); | |
} else { | |
var ratio = $(this).width() / parentWidth; | |
} | |
newSide = ratio * $(this).height(); | |
$(this).width(parentWidth); | |
if (newSide>parentHeight) { | |
$(this).css({'margin-top': parseInt((newSide - parentHeight)) * -1}); | |
} else { | |
$(this).css({'margin-top': parseInt((parentHeight - newSide)) * -1}); | |
} | |
} else { | |
$(this).height(parentWidth); | |
} | |
if ($(this).parent().hasClass('corners5')) { | |
$(this).parent().append('<div class="tr"></div><div class="tl"></div><div class="br"></div><div class="bl"></div>'); | |
} | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment