Skip to content

Instantly share code, notes, and snippets.

@tvlooy
Created December 16, 2011 19:48
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 tvlooy/1487643 to your computer and use it in GitHub Desktop.
Save tvlooy/1487643 to your computer and use it in GitHub Desktop.
The babe rotator - V2
<?php
function jpg ($file) { return substr($file, -4) == '.jpg'; }
$imgs = array_filter(scandir('.'), 'jpg');
$max = count($imgs);
shuffle($imgs);
?>
<html>
<body>
<img src="<?php echo $imgs[0]; ?>" id="cur_img" onclick="next();" height="100%" />
<img src="<?php echo $imgs[1]; ?>" id="nxt_img" onclick="next();" style="display: none;" />
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>
<script>
var cur = 0;
var max = <?php echo $max; ?>;
var imgs = [<?php foreach ($imgs as $img) echo "'$img'," ?>];
$(document).ready(function() { setInterval('next()', 10000); });
function next() {
cur++;
if (cur > max) cur = 0;
$("#cur_img").attr('src', $("#nxt_img").attr('src'));
$("#nxt_img").attr('src', imgs[cur]);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment