From 81bed997441dd40d5e1ecb1f7089960b6457c455 Mon Sep 17 00:00:00 2001 From: Michael Weichert Date: Fri, 2 Dec 2011 08:48:56 -0500 Subject: [PATCH] Added new option called 'scaling'. When this option is set to true, as well as the fit and aspect options, slides are never scaled (stretched). Instead, slides are always shrunk to fit into the container while maintaining the same aspect ratio. --- jquery.cycle.all.js | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/jquery.cycle.all.js b/jquery.cycle.all.js index d57fb72..51f3cd7 100644 --- a/jquery.cycle.all.js +++ b/jquery.cycle.all.js @@ -306,7 +306,7 @@ function buildOptions($cont, $slides, els, options, o) { $(els[first]).css('opacity',1).show(); // opacity bit needed to handle restart use case removeFilter(els[first], opts); - // stretch slides + // fit (and optionally stretch) slides into the container if (opts.fit) { if (!opts.aspect) { if (opts.width) @@ -316,16 +316,32 @@ function buildOptions($cont, $slides, els, options, o) { } else { $slides.each(function(){ var $slide = $(this); - var ratio = (opts.aspect === true) ? $slide.width()/$slide.height() : opts.aspect; - if( opts.width && $slide.width() != opts.width ) { - $slide.width( opts.width ); - $slide.height( opts.width / ratio ); - } - - if( opts.height && $slide.height() < opts.height ) { - $slide.height( opts.height ); - $slide.width( opts.height * ratio ); - } + var slide_width = $slide.width(); + var slide_height = $slide.height(); + var cont_width = $cont.width(); + var cont_height = $cont.height(); + var ratio = (opts.aspect === true) ? slide_width/slide_height : opts.aspect; + + if (slide_width != cont_width) { + if (slide_width > cont_width) { + $slide.width(slide_width=cont_width); + } + else if (opts.scaling !== false) { + $slide.width(slide_width=cont_width); + } + + $slide.height(slide_height=slide_width/ratio); + } + + if (slide_height != cont_height) { + if (slide_height > cont_height) { + $slide.height(slide_height=cont_height); + } + else if (opts.scaling !== false) { + $slide.height(slide_height=cont_height); + } + $slide.width(slide_width=slide_height*ratio); + } }); } }