Created
August 12, 2012 19:51
-
-
Save garethredfern/3334053 to your computer and use it in GitHub Desktop.
Simple Image Slider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Simple Image Slider</title> | |
<style> | |
.gallery { position: relative; width: 400px; height: 200px; } | |
.gallery figure { | |
top: 0; | |
left: 0; | |
width: 400px; | |
height: 200px; | |
position: absolute; | |
} | |
.gallery figcaption { | |
left: 0; | |
bottom: 0; | |
color: #FFF; | |
width: 390px; | |
padding: 5px; | |
position: absolute; | |
background-color: #323232; | |
} | |
</style> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> | |
</head> | |
<body> | |
<div class="gallery"> | |
<figure> | |
<img src="http://flickholdr.com/400/200/sea" alt=""> | |
<figcaption>Title One</figcaption> | |
</figure> | |
<figure> | |
<img src="http://flickholdr.com/400/200/sun" alt=""> | |
<figcaption>Title Two</figcaption> | |
</figure> | |
<figure> | |
<img src="http://flickholdr.com/400/200/sand" alt=""> | |
<figcaption>Title Three</figcaption> | |
</figure> | |
</div> | |
</body> | |
<script src="slider.js"></script> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var imgCount = $('.gallery figure').length; | |
console.log(imgCount); | |
if (imgCount > 1) { | |
$('.gallery figure:gt(0)').hide(); | |
setInterval(function() { | |
$('.gallery figure:first-child').fadeOut('slow') | |
.next('figure').fadeIn('slow') | |
.end().appendTo('.gallery'); | |
},5000); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment