Skip to content
Browse files

#111; fix cycle lite currSlide issue with fadeout

  • Loading branch information...
1 parent 7a5b104 commit b1dc72bc44405523317e2a016972075a07437b16 @malsup committed May 2, 2012
Showing with 39 additions and 32 deletions.
  1. +39 −32 jquery.cycle.lite.js
View
71 jquery.cycle.lite.js
@@ -2,15 +2,16 @@
* jQuery Cycle Lite Plugin
* http://malsup.com/jquery/cycle/lite/
* Copyright (c) 2008-2012 M. Alsup
- * Version: 1.5 (05-MAR-2012)
+ * Version: 1.6 (02-MAY-2012)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
* Requires: jQuery v1.3.2 or later
*/
;(function($) {
+"use strict";
-var ver = 'Lite-1.5';
+var ver = 'Lite-1.6';
$.fn.cycle = function(options) {
return this.each(function() {
@@ -25,7 +26,8 @@ $.fn.cycle = function(options) {
var $slides = options.slideExpr ? $(options.slideExpr, this) : $cont.children();
var els = $slides.get();
if (els.length < 2) {
- window.console && console.log('terminating; too few slides: ' + els.length);
+ if (window.console)
+ console.log('terminating; too few slides: ' + els.length);
return; // don't bother
}
@@ -41,9 +43,9 @@ $.fn.cycle = function(options) {
// allow shorthand overrides of width, height and timeout
var cls = this.className;
- opts.width = parseInt((cls.match(/w:(\d+)/)||[])[1]) || opts.width;
- opts.height = parseInt((cls.match(/h:(\d+)/)||[])[1]) || opts.height;
- opts.timeout = parseInt((cls.match(/t:(\d+)/)||[])[1]) || opts.timeout;
+ opts.width = parseInt((cls.match(/w:(\d+)/)||[])[1], 10) || opts.width;
+ opts.height = parseInt((cls.match(/h:(\d+)/)||[])[1], 10) || opts.height;
+ opts.timeout = parseInt((cls.match(/t:(\d+)/)||[])[1], 10) || opts.timeout;
if ($cont.css('position') == 'static')
$cont.css('position', 'relative');
@@ -54,7 +56,7 @@ $.fn.cycle = function(options) {
var first = 0;
$slides.css({position: 'absolute', top:0}).each(function(i) {
- $(this).css('z-index', els.length-i)
+ $(this).css('z-index', els.length-i);
});
$(els[first]).css('opacity',1).show(); // opacity bit needed to handle reinit case
@@ -68,7 +70,8 @@ $.fn.cycle = function(options) {
$cont.hover(function(){this.cyclePause=1;}, function(){this.cyclePause=0;});
var txFn = $.fn.cycle.transitions[opts.fx];
- txFn && txFn($cont, $slides, opts);
+ if (txFn)
+ txFn($cont, $slides, opts);
$slides.each(function() {
var $el = $(this);
@@ -91,7 +94,7 @@ $.fn.cycle = function(options) {
opts.speedIn = opts.speed;
opts.speedOut = opts.speed;
- opts.slideCount = els.length;
+ opts.slideCount = els.length;
opts.currSlide = first;
opts.nextSlide = 1;
@@ -105,19 +108,20 @@ $.fn.cycle = function(options) {
if (opts.click && !opts.next)
opts.next = opts.click;
if (opts.next)
- $(opts.next).unbind('click.cycle').bind('click.cycle', function(){return advance(els,opts,opts.rev?-1:1)});
+ $(opts.next).unbind('click.cycle').bind('click.cycle', function(){return advance(els,opts,opts.rev?-1:1);});
if (opts.prev)
- $(opts.prev).unbind('click.cycle').bind('click.cycle', function(){return advance(els,opts,opts.rev?1:-1)});
+ $(opts.prev).unbind('click.cycle').bind('click.cycle', function(){return advance(els,opts,opts.rev?1:-1);});
if (opts.timeout)
this.cycleTimeout = setTimeout(function() {
- go(els,opts,0,!opts.rev)
+ go(els,opts,0,!opts.rev);
}, opts.timeout + (opts.delay||0));
});
};
function go(els, opts, manual, fwd) {
- if (opts.busy) return;
+ if (opts.busy)
+ return;
var p = els[0].parentNode, curr = els[opts.currSlide], next = els[opts.nextSlide];
if (p.cycleTimeout === 0 && !manual)
return;
@@ -129,7 +133,7 @@ function go(els, opts, manual, fwd) {
if ($.browser.msie)
this.style.removeAttribute('filter');
$.each(opts.after, function(i,o) { o.apply(next, [curr, next, opts, fwd]); });
- queueNext();
+ queueNext(opts);
};
if (opts.nextSlide != opts.currSlide) {
@@ -140,14 +144,14 @@ function go(els, opts, manual, fwd) {
opts.nextSlide = roll ? 0 : opts.nextSlide+1;
opts.currSlide = roll ? els.length-1 : opts.nextSlide-1;
} else {
- queueNext();
+ queueNext(opts);
}
- function queueNext() {
+ function queueNext(opts) {
if (opts.timeout)
- p.cycleTimeout = setTimeout(function() { go(els,opts,0,!opts.rev) }, opts.timeout);
+ p.cycleTimeout = setTimeout(function() { go(els,opts,0,!opts.rev); }, opts.timeout);
}
-};
+}
// advance slide forward or back
function advance(els, opts, val) {
@@ -165,17 +169,19 @@ function advance(els, opts, val) {
}
go(els, opts, 1, val>=0);
return false;
-};
+}
$.fn.cycle.custom = function(curr, next, opts, cb) {
var $l = $(curr), $n = $(next);
$n.css(opts.cssBefore);
- var fn = function() {$n.animate(opts.animIn, opts.speedIn, opts.easeIn, cb)};
+ var fn = function() {$n.animate(opts.animIn, opts.speedIn, opts.easeIn, cb);};
$l.animate(opts.animOut, opts.speedOut, opts.easeOut, function() {
$l.css(opts.cssAfter);
- if (!opts.sync) fn();
+ if (!opts.sync)
+ fn();
});
- if (opts.sync) fn();
+ if (opts.sync)
+ fn();
};
$.fn.cycle.transitions = {
@@ -195,6 +201,7 @@ $.fn.cycle.transitions = {
opts.cssBefore = { opacity: 1, display: 'block', zIndex: 1 };
opts.cssAfter = { display: 'none', zIndex: 0 };
opts.animOut = { opacity: 0 };
+ opts.animIn = { opacity: 1 };
}
};
@@ -205,21 +212,21 @@ $.fn.cycle.defaults = {
animIn: {},
animOut: {},
fx: 'fade',
- after: null,
- before: null,
+ after: null,
+ before: null,
cssBefore: {},
cssAfter: {},
- delay: 0,
- fit: 0,
+ delay: 0,
+ fit: 0,
height: 'auto',
metaAttr: 'cycle',
- next: null,
- pause: 0,
- prev: null,
- speed: 1000,
+ next: null,
+ pause: false,
+ prev: null,
+ speed: 1000,
slideExpr: null,
- sync: 1,
- timeout: 4000
+ sync: true,
+ timeout: 4000
};
})(jQuery);

0 comments on commit b1dc72b

Please sign in to comment.
Something went wrong with that request. Please try again.