Je suis actuellement en train de réaliser un diaporama qui puise une image aléatoirement dans un dossier toutes les 10 secondes. Il fonctionne bien ! La prochaine étape serait d'afficher le nom du fichier de l'image, en même temps que celle-ci (sans l'extension .jpeg, de préférence).
Auriez vous des pistes ?
Merci beaucoup !
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="js/jquery.js"></script>
</head>
<body>
<script type="text/javascript">var aDatas = [];</script>
<?php
$aImages = scandir('img');
$i = 0;
foreach($aImages as $iKey => $sImage) {
if (strpos($sImage, 'png') !== false || strpos($sImage, 'jpg') !== false) {
?>
<script type="text/javascript">
aDatas.push(<?php echo json_encode($sImage); ?>);
</script>
<?php
}
}
?>
<img src="">
<script>
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex ;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
shuffle(aDatas);
var i = 0;
setInterval(function() {
$('img').attr('src','img/' + aDatas[i]);
i++;
if (i == aDatas.length) {
i = 0;
}
}, 500)
</script>
</body>
</html>