From: Alexander Sadleir Date: Sat, 03 Sep 2011 15:54:47 +0000 Subject: Add image resizing to better fit screens X-Git-Url: https://maxious.lambdacomplex.org/git/?p=photocalendar.git&a=commitdiff&h=389dfc856faf902798bb18493dcebe8598504a09 --- Add image resizing to better fit screens --- --- a/common.inc.php +++ b/common.inc.php @@ -42,7 +42,15 @@ - + + + + + "; } else { -echo ''; +echo 'Photo for '.$displayDate.''; } ?>
--- /dev/null +++ b/js/jquery.imagefit.js @@ -1,1 +1,48 @@ - +/* jquery.imagefit + * + * Version 0.2 by Oliver Boermans + * + * Extends jQuery + * + */ +(function($) { + $.fn.imagefit = function(options) { + var fit = { + all : function(imgs){ + imgs.each(function(){ + fit.one(this); + }) + }, + one : function(img){ + $(img) + .width('100%').each(function() + { + $(this).height(Math.round( + $(this).attr('startheight')*($(this).width()/$(this).attr('startwidth'))) + ); + }) + } + }; + + this.each(function(){ + var container = this; + + // store list of contained images (excluding those in tables) + var imgs = $('img', container).not($("table img")); + + // store initial dimensions on each image + imgs.each(function(){ + $(this).attr('startwidth', $(this).width()) + .attr('startheight', $(this).height()) + .css('max-width', $(this).attr('startwidth')+"px"); + + fit.one(this); + }); + // Re-adjust when window width is changed + $(window).bind('resize', function(){ + fit.all(imgs); + }); + }); + return this; + }; +})(jQuery);