Skip to content

Instantly share code, notes, and snippets.

@kellishaver
Created February 17, 2009 06:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kellishaver/65608 to your computer and use it in GitHub Desktop.
Save kellishaver/65608 to your computer and use it in GitHub Desktop.
A very simple jQuery slideshow.
// -----------------------------------------------------------------
// A very simple jQuery slideshow. It requires a little more work
// on the part of the user, but this keeps the transition code tiny.
// -----------------------------------------------------------------
// CSS
// -----------------------------------------------------------------
#slideshow { width:200px; height:200px; }
.hidden { display:none; }
// -----------------------------------------------------------------
// HTML
// -----------------------------------------------------------------
<ul id="slideshow">
<li class="item1"><img src="image1.jpg" width="200" height="200" /></li>
<li class="item2 hidden"><img src="image2.jpg" width="200" height="200" /></li>
<li class="item3 hidden"><img src="image3.jpg" width="200" height="200" /></li>
<li class="item4 hidden"><img src="image4.jpg" width="200" height="200" /></li>
<li class="item5 hidden"><img src="image5.jpg" width="200" height="200" /></li>
</ul>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
var slides = [ "item1", "item2", "item3", "item4", "item5" ];
var i = 1;
$(document).ready(function(){
window.setInterval(function() {
if (i == 0) { current = 'item5'; } else { p = i - 1; current = slides[p]; }
swap_slides(current, slides[i]);
if(i < 4) { i++; } else { i=0; }
}, 8000);
});
function swap_slides(current,next) {
$('#news_slideshow li.'+current).fadeOut( function() {
$('#news_slideshow li.'+next).fadeIn();
});
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment