Created
March 30, 2013 19:52
-
-
Save MorningZ/5278101 to your computer and use it in GitHub Desktop.
jQueryMobile: Vertical Align listitem thumbnails
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
var jQM = {}; | |
jQM.ResizeImage = function (img, maxWidth, maxHeight) { | |
maxHeight = maxHeight || maxWidth; | |
var srcWidth = img.width; var srcHeight = img.height; | |
var ratio = [maxWidth / srcWidth, maxHeight / srcHeight]; | |
ratio = Math.min(ratio[0], ratio[1]); | |
return { width: parseInt(srcWidth * ratio), height: parseInt(srcHeight * ratio) }; | |
}; | |
$(document).bind('pagebeforeshow', function (e) { | |
$(e.target).find("img.ui-li-thumb").each(function () { | |
$(this).css('margin-top', ((80 - jQM.ResizeImage(this, 80).height) / 2)); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment