Skip to content

Instantly share code, notes, and snippets.

@jasonmelgoza
Created May 25, 2012 15:35
Show Gist options
  • Select an option

  • Save jasonmelgoza/2788822 to your computer and use it in GitHub Desktop.

Select an option

Save jasonmelgoza/2788822 to your computer and use it in GitHub Desktop.
A simple slideshow
.slides .slide-list {
list-style: none;
margin: 0;
padding: 0; }
.slides .slide-list li {
display: none; }
.slides .slide-list li.active {
display: block; }
.slides .slide-buttons {
list-style: none;
margin: 0;
padding: 0; }
.slides .slide-list {
list-style: none;
margin: 0;
padding: 0;
li {
display: none;
&.active {
display: block;
}
}
}
.slides .slide-buttons {
list-style: none;
margin: 0;
padding: 0
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="description" content="">
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<title>Slideshow</title>
<link rel="stylesheet" href="slides.css" media="screen">
<!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
</head>
<body class="Slideshow">
<div class="slides">
<ul class="slide-list">
<li><img src="http://dribbble.com/system/assets/753/3305/screenshots/571444/inset.png"></li>
<li><img src="http://dribbble.com/system/assets/753/3305/screenshots/426405/work3.png"></li>
<li><img src="http://dribbble.com/system/assets/753/3305/screenshots/423132/work_2.png"></li>
</ul>
<ul class="slide-buttons">
<li><a class="button prev" href="#">Previous</a></li>
<li><a class="button next" href="#">Next</a></li>
</ul>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="slides.js"></script>
</body>
</html>
// slides.js
// https://gist.github.com/2788822
(function($) {
"use strict"; $(".slide-buttons .next").click(function() {
var activeimg, firstimg, nextimg, slide;
slide = $(this).parents().filter(".slides").eq(0);
activeimg = slide.find(".slide-list li.active");
nextimg = activeimg.next();
firstimg = slide.find(".slide-list li:first");
activeimg.removeClass("active");
if (nextimg.is("li")) {
nextimg.addClass("active");
} else {
firstimg.addClass("active");
}
return false;
});
$(".slide-buttons .prev").click(function() {
var activeimg, lastimg, previmg, slide;
slide = $(this).parents().filter(".slides").eq(0);
activeimg = slide.find(".slide-list li.active");
previmg = activeimg.prev();
lastimg = slide.find(".slide-list li:last");
activeimg.removeClass("active");
if (previmg.is("li")) {
previmg.addClass("active");
} else {
lastimg.addClass("active");
}
return false;
});
return $(".slide-list > li:first").addClass("active");
})(jQuery);
# slides.js
# https://gist.github.com/2788822
(($) ->
"use strict"
$(".slide-buttons .next").click ->
slide = $(this).parents().filter(".slides").eq(0)
activeimg = slide.find(".slide-list li.active")
nextimg = activeimg.next()
firstimg = slide.find(".slide-list li:first")
activeimg.removeClass "active"
if nextimg.is("li")
nextimg.addClass "active"
else
firstimg.addClass "active"
false
$(".slide-buttons .prev").click ->
slide = $(this).parents().filter(".slides").eq(0)
activeimg = slide.find(".slide-list li.active")
previmg = activeimg.prev()
lastimg = slide.find(".slide-list li:last")
activeimg.removeClass "active"
if previmg.is("li")
previmg.addClass "active"
else
lastimg.addClass "active"
false
$(".slide-list > li:first").addClass("active")
) jQuery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment