キーフレームに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:あなたの要求ごととして
、ここでのJavaScriptのバージョンがあります。そのような作業を達成するための無限の方法があります。私はバニラ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%;
}
}
はJavaScript:
// 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);
[最後のフレームにCSS3アニメーションを停止]の可能な重複(http://stackoverflow.com/questions/4359627/stopping-a-css3-animation-on-last-frame ) –