Advertisement
Guest User

Untitled

a guest
Feb 15th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let pictures = [
  2.   "dounat-1",
  3.   "dounat-2",
  4.   "dounat-3",
  5.   "dounat-4",
  6.   "dounat-5",
  7.   "dounat-6"
  8. ];
  9.  
  10. let container = document.getElementsByClassName("container__item-second");
  11.  
  12. // 1. Pobieramy wszystkie notatki:
  13. let third = document.querySelectorAll(".container__item-third");
  14.  
  15. let fir = document.getElementById("1");
  16. let sec = document.getElementById("2");
  17. let thi = document.getElementById("3");
  18. let fort = document.getElementById("4");
  19. let fif = document.getElementById("5");
  20. let six = document.getElementById("6");
  21.  
  22. fir.addEventListener("click", function() {
  23.   changeButton(
  24.     document.getElementById("7"),
  25.     document.getElementById("13"),
  26.     pictures[0]
  27.   );
  28. });
  29. sec.addEventListener("click", function() {
  30.   changeButton(
  31.     document.getElementById("8"),
  32.     document.getElementById("14"),
  33.     pictures[1]
  34.   );
  35. });
  36. thi.addEventListener("click", function() {
  37.   changeButton(
  38.     document.getElementById("9"),
  39.     document.getElementById("15"),
  40.     pictures[2]
  41.   );
  42. });
  43. fort.addEventListener("click", function() {
  44.   changeButton(
  45.     document.getElementById("10"),
  46.     document.getElementById("16"),
  47.     pictures[3]
  48.   );
  49. });
  50. fif.addEventListener("click", function() {
  51.   changeButton(
  52.     document.getElementById("11"),
  53.     document.getElementById("17"),
  54.     pictures[4]
  55.   );
  56. });
  57. six.addEventListener("click", function() {
  58.   changeButton(
  59.     document.getElementById("12"),
  60.     document.getElementById("18"),
  61.     pictures[5]
  62.   );
  63. });
  64.  
  65. function changeButton(idImg, idParagraf, img) {
  66.   if (idImg.getAttribute("src") == "img/donut.png") {
  67.  
  68. // 2. Iterujemy po wszystkich notatkach, czyli pętlą for przeskakujemy po wszystkich i wszsytkim nadajemy "display: none"
  69.     for (let i = 0; i < third.length; i++) {
  70.       third[i].style = "display: none";
  71.     }
  72.  
  73.     idImg.src = "img/" + img + ".jpg";
  74.  
  75. // 3. Do paragrafu który chcemy wyświetlic dodajemy display: block:
  76.     idParagraf.style = "display: block";
  77.     idParagraf.className = "container__item-third__visible";
  78.  
  79.     // let sib = this.nextElementSibling
  80.     //sib.src="img/donut.png"
  81.   } else {
  82.     idImg.src = "img/donut.png";
  83.     idParagraf.setAttribute("class", "container__item-third");
  84.   }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement