Created
December 16, 2011 19:48
-
-
Save tvlooy/1487643 to your computer and use it in GitHub Desktop.
The babe rotator - V2
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
<?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