Skip to content

Instantly share code, notes, and snippets.

@kara-ryli
Created January 30, 2010 00:04
Show Gist options
  • Save kara-ryli/290283 to your computer and use it in GitHub Desktop.
Save kara-ryli/290283 to your computer and use it in GitHub Desktop.
A Webkit-only version of Jonathon Snook's "Simplest jQuery Slideshow" that meets his requirements (concise, less than 20 lines) without requiring jQuery.
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Simplest jQuery Slideshow</title>
<style>
body { font-family:Arial, Helvetica, sans-serif; font-size:12px; }
.fadein { position:relative; height:332px; width:500px; }
.fadein img { position:absolute; left:0; top:0;}
.fadein.ready img { -webkit-transition: opacity 1s linear;}
</style>
</head>
<body>
<h1>Simplest Webkit Slideshow</h1>
<p>Check out the <a href="http://snook.ca/archives/javascript/simplest-webkit-slideshow">blog post</a>.</p>
<div class="fadein">
<img src="http://farm3.static.flickr.com/2610/4148988872_990b6da667.jpg">
<img src="http://farm3.static.flickr.com/2597/4121218611_040cd7b3f2.jpg">
<img src="http://farm3.static.flickr.com/2531/4121218751_ac8bf49d5d.jpg">
</div>
<script>
(function () {
var div = document.querySelector('.fadein'), l = div.getElementsByTagName('img').length, i;
function setSlideOpacity(n, o) {
div.querySelector('img:nth-child(' + n + ')').style.opacity = o;
}
for (i = l; i > 1; i--) {
setSlideOpacity(i, 0);
}
setTimeout(function() {
div.className += ' ready';
setInterval(function() {
setSlideOpacity(i, 0);
i = (i === l)? 1 : i + 1;
setSlideOpacity(i, 1);
}, 3000);
}, 1000);
}());
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment