forked from mathiasbynens/jquery-slideshow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.slideshow.js
27 lines (27 loc) · 1.03 KB
/
jquery.slideshow.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*!
* Simplest jQuery Slideshow Plugin v1.0
* @link http://github.com/mathiasbynens/Simplest-jQuery-Slideshow
* @author Mathias Bynens <http://mathiasbynens.be/>
*/
;(function($) {
$.fn.slideshow = function(options) {
options = $.extend({
timeout: 3000,
speed: 400 // 'normal'
}, options);
// We loop through the selected elements, in case the slideshow was called on more than one element e.g. `$('.foo, .bar').slideShow();`
return this.each(function() {
// Inside the setInterval() block, `this` references the window object instead of the slideshow container element, so we store it inside a var
var $elem = $(this);
$elem.children().eq(0).appendTo($elem).show();
// Iterate through the slides
setInterval(function() {
$elem.children().eq(0)
// Hide the current slide and append it to the end of the image stack
.hide().appendTo($elem) // As of jQuery 1.3.2, .appendTo() returns the inserted element
// Fade in the next slide
.fadeIn(options.speed)
}, options.timeout);
});
};
})(jQuery);