Skip to content

Instantly share code, notes, and snippets.

@MorningZ
Created March 30, 2013 19:52
Show Gist options
  • Save MorningZ/5278101 to your computer and use it in GitHub Desktop.
Save MorningZ/5278101 to your computer and use it in GitHub Desktop.
jQueryMobile: Vertical Align listitem thumbnails
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