Created
June 25, 2009 15:40
-
-
Save philsturgeon/135930 to your computer and use it in GitHub Desktop.
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
/* | |
* jQuery Cycle plugin v0.2 | |
* Philip Sturgeon [http://philsturgeon.co.uk] | |
* | |
* Licensed under the WTFPL License | |
* http://sam.zoy.org/wtfpl/ | |
*/ | |
(function($) | |
{ | |
$.fn.cycle = function (interval, options) | |
{ | |
// Nothing passed, lets use a default start with a 1 second loop | |
if(typeof interval == 'undefined' && typeof options == 'undefined') | |
{ | |
interval = 1000; | |
} | |
// Only options are passed | |
else if(typeof interval == 'object' && typeof options == 'undefined') | |
{ | |
options = interval; | |
interval = 1001; | |
} | |
// define defaults and override with options, if available | |
// by extending the default settings, we don't modify the argument | |
settings = jQuery.extend({ | |
action: 'start', | |
children: '', | |
instance: '', | |
}, options); | |
switch(settings.action) | |
{ | |
case 'start': | |
this.each(function() | |
{ | |
// Hide all children but the first | |
$(this).children(settings.children + ':not(:first)').hide(); | |
var current = 1; // First entry is 0, but we 1 is already showing | |
var total_children = $(this).children().length; | |
cycle = this; | |
timer = $.timer(interval, function(){ | |
$(cycle).children(settings.children + ':eq(' + current.toString() + ')').show().siblings(settings.children).hide(); | |
// Increment to next child | |
current++; | |
// Next child is the same as the total, set back to zero | |
if(current == total_children) current = 0; | |
}); | |
}); | |
return timer; | |
break; | |
// END case 'start' | |
case 'stop': | |
settings.instance.stop(); | |
break; | |
case 'next': | |
alert('next!'); | |
break; | |
case 'previous': | |
alert('previous!'); | |
break; | |
} | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment