키 프레임에 99 % 정도를 추가하고 불투명도를 1로 설정하십시오. 처음에 opacity: 1
이있는 경우 99 %까지 그대로 유지됩니다. 100 % 만 변경됩니다.
기술적으로 100 % 해고 된 것은 아닙니다. 원한다면 여기 JavaScript를 사용하는 것이 좋겠지 만 이것은 적어도 당신이 원하는 환상을 줄 것입니다.
@keyframes slide {
0% {
left: 0;
}
20% {
left: 20%;
}
40% {
left: 40%;
}
60% {
left: 60%;
}
80% {
left: 80%;
}
99% {
opacity: 1;
}
100% {
left: 100%;
overflow: hidden;
opacity: 0;
display: none;
visibility: hidden;
}
}
UPDATE : 귀하의 요청에 따라
가 여기에 자바 스크립트 버전입니다. 이러한 작업을 수행하는 데는 끝없는 방법이 있습니다. 바닐라 JS (jQuery 등 없음)를 사용하고 있고 ES6 구문을 사용하고 있습니다.
우리가 여기에서하는 일은 시간 초과를 설정하고 그 시간 만료 후 나는 animation_end
이벤트를 방송합니다. 이 이벤트 리스너는 애니메이션의 끝을 처리합니다 (이 경우에는 페이드 아웃을 처리 할 클래스를 추가합니다). 이것은 당신이 필요로하는 것보다 훨씬 세분화 된 것입니다. 단순히 setTimeout 내에 클래스를 추가하는 것만으로도 가능 합니다만, 애니메이션 시작과 같은 이벤트로 추상화 할 수 있으므로이 방법이 약간 더 좋다고 생각합니다. 기타여기
는 바이올린입니다 :
https://jsfiddle.net/vmyzyd6p/
HTML :
<div class="container">
<div class="slide-box" id="slide-box""></div>
</div>
CSS :
.slide-box {
position: relative;
width: 100px;
height: 100px;
background-color: blue;
animation: slide 3s linear 1;
-webkit-transition: opacity 2s ease-in-out;
-moz-transition: opacity 2s ease-in-out;
transition: opacity 2s ease-in-out;
}
.animationEnd {
opacity: 0;
}
@keyframes slide {
0% {
left: 0;
}
20% {
left: 20%;
}
40% {
left: 40%;
}
60% {
left: 60%;
}
80% {
left: 80%;
}
100% {
left: 100%;
}
}
자바 스크립트 :
// Create a function that handles the `animation_end` event
const animationEnd =() => {
// Grab the slidebox element
let slideBox = document.getElementById('slide-box');
// Get the class of the slidebox element
let slideClass = slideBox.getAttribute('class');
// Add the animation end class appended to the previous class
slideBox.setAttribute('class', slideClass + ' animationEnd');
};
// Create the animation end event
let animationEndEvent = new Event('animation_end');
// Cross browser implementation of adding the event listener
if (document.addEventListener) {
document.addEventListener('animation_end', animationEnd, false);
} else {
document.attachEvent('animation_end', animationEnd);
}
// Set the timeout with the same duration as the animation.
setTimeout(() => {
// Broadcast the animation end event
document.dispatchEvent(animationEndEvent);
}, 3000);
가능한 복제 (http://stackoverflow.com/questions/4359627/stopping-a-css3-animation-on-last-frame) –