Skip to content

Instantly share code, notes, and snippets.

@joshtronic
Created November 9, 2010 04:11
Show Gist options
  • Save joshtronic/668686 to your computer and use it in GitHub Desktop.
Save joshtronic/668686 to your computer and use it in GitHub Desktop.
/**
* JJ Slider (jQuery Slideshow) Plug-In
*
* http://github.com/joshtronic/jquery.jjslider
*
* Author: Josh Sherman <[email protected]>
* Copyright (c) 2010 Gravity Boulevard, LLC
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
(function($)
{
$.fn.extend(
{
jjslider: function(options)
{
defaults = {
};
options = $.extend(defaults, options);
return this.each(function()
{
var image_count = $('img').length;
$(this).css('position', 'relative');
$('img', this)
.css('position', 'absolute')
.css('top', 0)
.css('left', 0)
.css('z-index', image_count)
.css('opacity', 0.0)
;
$('img:first', this)
.css('z-index', image_count + 1)
.css('opacity', 1.0)
.addClass('active')
;
var context = $(this);
var timer = setInterval(function(){ jjTransition(context, image_count); }, 3000);
});
function jjTransition(slider, image_count)
{
var active = $('img.active', slider);
var next = active.next().length ? active.next() : $('img:first', slider);
active
.addClass('last-active')
.css('z-index', image_count + 1)
;
next
.css({opacity: 0.0})
.addClass('active')
.css('z-index', image_count + 2)
.animate(
{opacity: 1.0},
1000,
function()
{
active
.removeClass('active last-active')
.css('z-index', image_count + 1)
.css('opacity', 0.0)
;
})
;
}
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment