Skip to content

Instantly share code, notes, and snippets.

@amadeus
Created August 21, 2012 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amadeus/3420258 to your computer and use it in GitHub Desktop.
Save amadeus/3420258 to your computer and use it in GitHub Desktop.
Ghetto Slideshow
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Slideshow</title>
<style type="text/css">
html, body { margin:0; padding:0; }
img { display:block; margin:0 auto; }
</style>
</head>
<body oncontextmenu="return false;">
<!-- Add any number of images -->
<img src="lion.jpg" alt="" />
<img src="tubes.jpg" alt="" />
<img src="zx10.jpg" alt="" />
<!-- Make sure this is always AFTER all images -->
<script type="text/javascript">
var els = Array.prototype.slice.call(document.getElementsByTagName('img')),
i = els.length - 1,
clean = function(){
for (var x = 0; x < els.length; x++){
if (els[x].parentNode)
els[x] = els[x].parentNode.removeChild(els[x]);
}
},
cycle = function(e){
if (e && e.preventDefault) e.preventDefault();
if (e && e.ctrlKey){
i -= 2;
return cycle();
}
i++;
if (i >= els.length) i = 0;
if (i < 0) i = els.length - 1;
clean();
document.body.appendChild(els[i]);
};
cycle();
document.body.addEventListener('click', cycle, false);
document.body.addEventListener('mousedown', function(e){ if (e && e.preventDefault) e.preventDefault(); }, false);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment