formkit / auto-animate

A zero-config, drop-in animation utility that adds smooth transitions to your web app. You can use it with React, Vue, or any other JavaScript application.

Home Page:https://auto-animate.formkit.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Accordion animation in Native JS

HipyCas opened this issue · comments

I am trying to get auto-animate working with an accordion and pure JS, yet it isn't working, but with a list it is. My code is the following:

    <div class="faq">
      <h4 class="header">
        Title of the question
      </h4>
      <div class="content" hidden>Nice stuff here</div>
    </div>

<script type="module">
import autoAnimate from "https://cdn.jsdelivr.net/npm/@formkit/auto-animate@1.0.0-beta.1/index.min.js";

const faq_header = document.querySelector(".faq > .header");
const faq_content = document.querySelector(".faq > .content");

faq_header.addEventListener("click", () => {
  faq_content.toggleAttribute("hidden");
});

autoAnimate(faq);
</script>

How can I set this up to work?

Your situation needs to conform to one of these:

image

Adding/removing the "hidden" attribute does not satisfy those. You could re-write yoru code to use .remove() and .appendChild() (or similar) to get it working.