Показать сообщение отдельно
  #7 (permalink)  
Старый 06.05.2020, 22:49
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,075

вариант добавления класса с помощью setTimeout
Сообщение от nastya97core
А если бы у меня таких 10 моментов
<!doctype html>
<html lang="ru">
<head>
        <meta charset="UTF-8">
        <title>Document</title>
        <style type="text/css">
form.err .anima{
animation:anima 350ms backwards ease-in-out;
color: red;
}

@keyframes anima {
from {transform: translateX(0);}
20% {transform: translateX(1%);}
40% {transform: translateX(-1%);}
60% {transform: translateX(1%);}
80% {transform: translateX(-1%);}
to {transform: translateX(0);}
}
        </style>

    <script>
document.addEventListener( "DOMContentLoaded" , function() {
let timer;
document.querySelector("button").onclick = function(){
    clearTimeout(timer);
    document.querySelector("form").classList.remove("err");
    timer = setTimeout(()=> document.querySelector("form").classList.add("err"))
}
    });
    </script>

</head>
<body>
<form action="http://">

<h1 class="anima">Анимация</h1>
<h1 class="anima">Анимация</h1>
<h1 class="anima">Анимация</h1></form>
<button>Жмай</button>
</body>
</html>
Ответить с цитированием