このような CSS キーフレーム アニメーションがある場合
@keyframes flash-red {
50% {
background: #f00;
}
}
#goflash.anm-flash {
animation-name: flash-red;
animation-duration: .5s;
background: rgba(255, 0, 0, 0);
}
次に、次のようにいつでもアニメーションをトリガーできます。
var gf = document.querySelector("#goflash");
gf.classList.remove("anm-flash");
setTimeout(function() {
gf.classList.add("anm-flash");
}, 50);
animation-duration/animation-timing-function を JavaScript に依存するようにオーバーライドする方法はありますか? gf.animate("flash-red", "50%")
背景をgf
赤にするとか、gf.animate("flash-red", "75%")
背景をもっとrgba(255, 0, 0, .5)
.
理想的には、同じ手法がトランジションにも機能します。gf.transitionTo("new-class", "50%")
途中で遷移した要素を表示します。
明らかに、これflash-red
は単なる例です。どのアニメーションでもこれを実行できるようにしたいと考えています。