Представьте, что у меня есть 3 div:
<div class="one animated">
I'm the first div
</div>
<div class="two">
second div
</div>
<div class="three">
Last one
</div>
У меня есть код для перемещения первого в начало:
.animated {
animation: animation 2s;
animation-fill-mode: forwards;
}
@keyframes animation {
0% { top: 0; opacity: 1 }
100% { top: -300px; opacity: 0 }
}
Я не понимаю, почему первый div перемещается в сверху, но не остальные. Первый исчезает, поэтому я хочу заменить пустое поле другим моим div ...
Что-то вроде этого:
function test() {
document.getElementById("sample").classList.add("animated");
}
.one {
border: 1px solid red;
}
.animated {
animation: animation 2s;
animation-fill-mode: forwards;
}
@keyframes animation {
0% { top: 0; opacity: 1 }
100% { top: -300px; opacity: 0 }
}
<div class="one" id="sample">
I'm the first div
</div>
<div class="two">
second div
</div>
<div class="three">
Last one
</div>
<button onclick="test()">Test</button>