Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 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. // Initialize
  46. new Accordion();
  47.  
  48. function Accordion() {
  49.  
  50. this.accordion = document.querySelectorAll('.accordion-item');
  51.  
  52. this.init = () => {
  53. this.toggleAccordion(this.accordion);
  54. }
  55.  
  56. this.toggleAccordion = function(array) {
  57. array.forEach((element) => {
  58. element.addEventListener('click', () => {
  59.  
  60. if(element.classList.contains('accordion-active')) {
  61. element.classList.remove('accordion-active');
  62. return;
  63. }
  64.  
  65. this.removeActiveClass();
  66.  
  67. element.classList.add('accordion-active');
  68. });
  69. });
  70. }
  71.  
  72. this.removeActiveClass = function() {
  73. this.accordion.forEach((element) => {
  74. element.classList.remove('accordion-active');
  75. })
  76. }
  77.  
  78. }
  79.  
  80. var accordion = new Accordion();
  81. accordion.init();
  82.  
  83. </script>
  84.  
  85. </body>
  86. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement