Skip to content

Instantly share code, notes, and snippets.

@yramagicman
Last active December 12, 2015 12:48
Show Gist options
  • Save yramagicman/4774111 to your computer and use it in GitHub Desktop.
Save yramagicman/4774111 to your computer and use it in GitHub Desktop.
Simple function to loop through elements in a slideshow/slider format
var loop = function (wrapper, kids, fade, delay) {
var count = $(wrapper).children().length,
selector = [];
$(wrapper).children().fadeOut(0);
for (var i = 1; i < count + 1; i++) {
selector[i] = $(wrapper + ' ' + kids + ':nth-child(' + i + ')');
}
var z = 1;
selector[z].each(function () {
$(this).fadeIn(fade).delay(delay).fadeOut(fade, function () {
$(this).remove().appendTo(wrapper);
}); //end callback
});
};
var play = function (wrapper, kids, fade, delay) {
setInterval(function () {
loop(wrapper, kids, fade, delay);
}, 0);
};
var pause = function () {
//gotta think about this one.
};
play('#slider', 'div', 2000, 7000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment