Вы можете использовать jQuery-метод css() в сочетании со свойством animation-play-state для воспроизведения и остановки анимации CSS в середине цикла.
Давайте посмотрим на следующий пример, чтобы понять, как это работает:
<!DOCTYPE html>
<html lang="en">
<head>
<title>jQuery Play and Stop CSS Animation</title>
<style>
.animated {
height: 200px;
margin: 10px 0;
background: url("smiley.png") no-repeat left center #e4eacf;
-webkit-animation: test 4s infinite; /* Chrome, Safari, Opera */
animation: test 4s infinite;
}
/* Chrome, Safari, Opera */
@-webkit-keyframes test {
50% {background-position: right center;}
}
/* Standard syntax */
@keyframes test {
50% {background-position: right center;}
}
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
$(".play-animation").click(function(){
$(".animated").css("animation-play-state", "running");
});
$(".stop-animation").click(function(){
$(".animated").css("animation-play-state", "paused");
});
});
</script>
</head>
<body>
<div class="animated"></div>
<button type="button" class="play-animation">Воспроизвести анимацию</button>
<button type="button" class="stop-animation">Остановить анимацию</button>
<p><strong>Предупреждение:</strong> CSS-анимация не работает в Internet Explorer 9 и более ранних версиях.</p>
</body>
</html>
















