Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. // HTML Markup
  2.  
  3. // <div class="accordion">First</div>
  4. // <p class="accordtion_text">Lorem 1</p>
  5. // <div class="accordion">Second</div>
  6. // <p class="accordtion_text">Lorem 2</p>
  7. // <div class="accordion">Third</div>
  8. // <p class="accordtion_text">Lorem 3</p>
  9.  
  10. // CSS Styles
  11.  
  12. // .accordion {
  13. // width: 100%;
  14. // padding: 10px;
  15. // font-size: 20px;
  16. // background-color: #eee;
  17. // margin-bottom: 5px;
  18. // }
  19. // .accordtion_text {
  20. // display: none;
  21. // padding: 10px;
  22. // font-size: 16px;
  23. // animation-name: fade;
  24. // animation-duration: 0.5s;
  25. // }
  26. // @keyframes fade {
  27. // from{opacity: 0.1}
  28. // to{opacity: 1}
  29. // }
  30. // .accordtion_text.show {
  31. // display: block;
  32. // }
  33.  
  34. // JS Code
  35.  
  36. let acc = document.getElementsByClassName("accordion");
  37. let i;
  38. for (i = 0; i < acc.length; i++) {
  39. acc[i].onclick = function () {
  40. this.classList.toggle("active");
  41. this.nextElementSibling.classList.toggle("show");
  42. };
  43. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement