Trigger CSS Animations in JavaScript

后端 未结 8 1170
粉色の甜心
粉色の甜心 2020-11-28 14:14

I don\'t know how to use JQuery, so I need a method which could trigger an animation using JavaScript only.

I need to call/trigger CSS Animation when the user scrol

8条回答
  •  春和景丽
    2020-11-28 14:38

    If you want Animations i recommend you create a CSS class which you toggle on a Condition whit JS: CSS

    .animation {
     animation: anim 2s ease infinite;
     transition: .2s
    }
    

    JS

    // Select your Element
    
    $element.document.querySelector(".yourElement");
    $element.addEventListner('click', () => {
     $element.classList.toggle("animation")
    })
    

提交回复
热议问题