Advertisement
Tauron28

Untitled

Jan 27th, 2022
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const accordion = (triggerSelector) =>{
  2.     const btns = document.querySelectorAll(triggerSelector);
  3.  
  4.     btns.forEach(btn =>{
  5.         btn.addEventListener('click', function() {
  6.             this.classList.toggle('active-style');
  7.             this.nextElementSibling.classList.toggle('active-content');
  8.  
  9.             if(this.classList.contains('active-style')){
  10.                 this.nextElementSibling.style.maxHeight= this.nextElementSibling.scrollHeight + 80 + "px";
  11.             }else{
  12.                 this.nextElementSibling.style.maxHeight = '0px';
  13.             }            
  14.         })
  15.     })
  16.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement