<p>Різні значення для <code>animation-fill-mode</code> у дії:</p>
<button id="btn">Запустити анімацію</button>
<hr>
<div class="wrapper">
<div class="block block-1">
<span>none</span>
</div>
<div class="block block-2">
<span>forwads</span>
</div>
<div class="block block-3">
<span>backwards</span>
</div>
<div class="block block-4">
<span>both</span>
</div>
</div>
body {
padding: 36px;
text-align: center;
font-family: monospace;
font-size: 17px;
color: #222;
line-height: 1.45;
}
#btn {
cursor: pointer;
width: 250px;
text-align: center;
padding: 6px 12px;
font-size: 19px;
display: inline-block;
}
@keyframes animate {
from {
margin-top: 50px;
}
to {
margin-top: 100px;
}
}
.wrapper {
display: flex;
justify-content: space-between;
align-items: flex-start;
}
.block {
background-color: red;
padding: 26px 8px;
width: 125px;
text-align: center;
color: #fff;
font-size: 15px;
border: 2px solid rgba(255, 255, 255, .45);
animation-name: animate;
animation-duration: 1.25s;
animation-timing-function: ease-in;
animation-delay: 0s;
animation-iteration-count: 1;
animation-direction: normal;
animation-play-state: paused;
}
.block-1 {
animation-fill-mode: none;
}
.block-2 {
animation-fill-mode: forwads;
}
.block-3 {
animation-fill-mode: backwards;
}
.block-4 {
animation-fill-mode: both;
}
var blocks = document.getElementsByClassName('block');
var btn = document.getElementById('btn');
btn.onclick = function() {
for (var i = 0; i < blocks.length; i++) {
blocks[i].style.animationPlayState = 'running';
}
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.