Advertisement
Guest User

JS 09

a guest
Apr 23rd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var audio = document.getElementById('myAudio');
  2. var source = document.getElementById('audioSource');
  3. var CurrentIndex;
  4.  
  5.  
  6. // populate all pics
  7. var allImages = ''
  8. for (i = 0; i < 12; i++) {
  9.  var eachPic =
  10.    '<div class="col-sm-4"  id="Pic' + i + '" onclick="flipOver(' + i + ')">'
  11.  eachPic += '<img src="Pictures/' + i + '1.png"></div>'
  12.  allImages += eachPic
  13. }
  14.  
  15.  
  16. document.getElementById('allpics').innerHTML = allImages
  17. function playAudio(index) {
  18.     source.src = "Audio/" + index + "2.mp3";
  19.     audio.load();
  20.     audio.play();
  21. }
  22.  
  23.  
  24. function flipOver(index) {
  25.     var name = (document.getElementById("Pic" + index).innerHTML).trim();
  26.     var vertxt = '<img src="Pictures/' + index + '1.png">';
  27.     var verimg = '<img src="Pictures/' + index + '0.jpg">';
  28.     if (name[name.length - 7] == "1") {
  29.         document.getElementById("Pic" + index).innerHTML = verimg
  30.         setTimeout(FlipBack, 3000, index);
  31.         CurrentIndex = index;
  32.         playAudio(index);
  33.     }
  34. }
  35.  
  36.  
  37.  
  38. function FlipBack(Num) {
  39.     var vertxt = '<img src="Pictures/' + Num + '1.png">';
  40.     document.getElementById("Pic" + Num).innerHTML = vertxt;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement