Expand the accordion at a specific screen resolution?

  • 0
    Good afternoon, can you please tell me how to change js so that the accordion is deployed by default only on desktops (or at certain screen resolutions)?
    var acc = document.getElementsByClassName("accordion-filter");
    var i;
    
    for (i = 0; i < acc.length; i++) {
      acc[i].addEventListener("click", function() {
        this.classList.toggle("active-filter");
        var panel = this.nextElementSibling;
        if (panel.style.maxHeight){
          panel.style.maxHeight = null;
        } else {
          panel.style.maxHeight = panel.scrollHeight + "px";
        }
      });
    }
    JavaScript Anonymous, May 8, 2020

  • 1 Answers
  • 0
    You must calculate the width using

    window.innerWidth

    You get the screen width, and then through the condition "if & gt; 768px then this if & lt; something else "

    Also with height you can
    Everly Durham

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!