SHARE
TWEET

Changement diaporama flèches du clavier solution 2

a guest Jul 16th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function diapoSuivante() {
  2. affichage (diaporama ++);
  3. }
  4.  
  5. function diapoPrecedente() {
  6. affichage (diaporama --);
  7. }
  8.    document.addEventListener("keydown", function(touche){
  9.     if(touche.keyCode === 37){
  10.         return diapoPrecedente();
  11.     }
  12.     else if(touche.keyCode === 39){
  13.         return diapoSuivante();
  14.     }
  15.     });
  16.  
  17.  
  18.  
  19. // Reste du script JS
  20. var diaporama = 1;
  21. affichage(diaporama);
  22.  
  23. function boutons(n) {
  24. affichage(diaporama += n);
  25. }
  26. function affichage(n) {
  27. var i;
  28. var diapoImg = document.getElementsByClassName("diapo");
  29. var diapo = document.getElementsByClassName("demo");
  30. if (n > diapoImg.length) {diaporama = 1}
  31. if (n < 1) {diaporama = diapoImg.length}
  32. for (i = 0; i < diapoImg.length; i++) {
  33.  
  34. diapoImg[i].style.opacity = "0";
  35. }
  36. for (i = 0; i < diapo.length; i++) {
  37. diapo[i].className = diapo[i].className.replace("numeros");
  38. }
  39. diapoImg[diaporama-1].style.opacity = "1";
  40. diapo[diaporama-1].className += "numeros";
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top