dimanche 22 juillet 2018

Display random image with specific audio on page load

Im trying to re purpose some code. I have a program that displays a random image on page load. Im trying to re build it so that it loads a random image WITH a specified sound effect for each image. Im trying to achieve that by having the page load a random div with all the relevant content, but I think ive made some huge missteps and am chasing my tail. Any help setting this up would be amazing please and thanks!

=========================================================================

<script type="text/javascript">
var lastIndex = 0;

function randomCard() {
var theCard = document.getElementById('myCard');
var divArray = new Array

(
'<div id=card><Image id="Image1" src="MyImages/image1.gif"></image><audio 
src="MyAudio/Audio1.mp3" autoplay="autoplay"></audio></div>',
'<div id=card><Image id="Image2" src="MyImages/image2.gif"></image><audio 
src="MyAudio/Audio1.mp3" autoplay="autoplay"></audio></div>',
'<div id=card><Image id="Image2" src="MyImages/image3.gif"></image><audio 
src="MyAudio/Audio1.mp3" autoplay="autoplay"></audio></div>'
);

var divIndex = 0;

if(divArray.length > 1) {
while(divIndex == lastIndex) {
divIndex = Math.floor(Math.random() * divArray.length);
}
lastIndex = divIndex;


}
else {
return false;
}
}
</script>

</head>
<body onload="randomCard()">

<div id=card></div>




Aucun commentaire:

Enregistrer un commentaire