Skip to content

Instantly share code, notes, and snippets.

View amnuts's full-sized avatar

Andrew Collington amnuts

View GitHub Profile
@amnuts
amnuts / crossfade.js
Last active December 27, 2015 08:59
Quick and easy way to cross-fade between elements in a list. If those elements contained images then you have a very simple slideshow. (Requires jQuery.)
if ($('ul.crossfade').length) {
$('ul.crossfade').each(function(){
var ul = $(this);
if ($('li', ul).length > 1) {
$('li:gt(0)', ul).hide();
var fadeSpeed = (ul.attr('data-fadespeed') !== undefined ? ul.attr('data-fadespeed') : 1000);
var nextSpeed = (ul.attr('data-nextspeed') !== undefined ? ul.attr('data-nextspeed') : 5000);
setInterval(function(){
$('li:first', ul)
.fadeOut(fadeSpeed).next('li')