Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Project Template</title>
  5.  
  6. <style type="text/css">
  7. body {
  8. margin-left: auto;
  9. margin-right: auto;
  10. max-width: 40em;
  11. width: 88%;
  12. }
  13.  
  14. .accordion-content {
  15. display: none;
  16. }
  17.  
  18. .accordion-active .accordion-content {
  19. display: block;
  20. }
  21. </style>
  22. </head>
  23. <body>
  24.  
  25. <h1>Accordion</h1>
  26.  
  27. <div class="accordion">
  28. <div class="accordion-item">
  29. <h2 class="accordion-title">Man-of-War</h2>
  30. <div class="accordion-content"><p>Prow clipper capstan grog poop deck. Hands man-of-war interloper measured fer yer chains no prey, no pay. Spanish Main dead men tell no tales hands spirits Pieces of Eight.</p></div>
  31. </div>
  32.  
  33. <div class="accordion-item">
  34. <h2 class="accordion-title">Cutlass</h2>
  35. <div class="accordion-content"><p>Yard blow the man down execution dock broadside barque. Pressgang bilge hang the jib Spanish Main driver. Belay red ensign cutlass chantey trysail.</p></div>
  36. </div>
  37.  
  38. <div class="accordion-item">
  39. <h2 class="accordion-title">Pirate Draft</h2>
  40. <div class="accordion-content"><p>Main sheet gunwalls tender Admiral of the Black Cat o'nine tails. Bring a spring upon her cable parrel gangplank pirate draft. Rutters bilge rat driver ballast swing the lead.</p></div>
  41. </div>
  42. </div>
  43.  
  44. <script>
  45. // Class for Accordion
  46. class Accordion {
  47. constructor() {
  48. this.accordion = document.querySelectorAll('.accordion-item');
  49. this.toggleAccordion(this.accordion);
  50. }
  51.  
  52. toggleAccordion(array) {
  53. array.forEach(element => {
  54. element.addEventListener('click', () => {
  55.  
  56. if(element.classList.contains('accordion-active')) {
  57. element.classList.remove('accordion-active');
  58. return;
  59. }
  60.  
  61. this.removeActiveClass();
  62.  
  63. element.classList.add('accordion-active');
  64. });
  65. });
  66. }
  67.  
  68. removeActiveClass() {
  69. this.accordion.forEach((element) => {
  70. element.classList.remove('accordion-active');
  71. })
  72. }
  73. }
  74.  
  75. // Initialize
  76. new Accordion();
  77.  
  78. </script>
  79.  
  80. </body>
  81. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement