&を使用CSS3 animations
してトリガーすることができます...これで、キー
を押すだけで効果をアクティブにできます...:focus
:active
TAB
mouse clickしかし、それを.... でアクティブにするa tag
必要があり、オブジェクトにフォーカスを設定する必要がある場合は、いくつかjavascript
が必要です。(この場合はインライン)
別のオブジェクトを使用できる場合は、を実行input type="text"
するfocus
と自動的に設定されますclick
が、この場合focus
はブラウザによって指定されたアクションです。
したがって、必要なインライン JS は次のとおりです。
<a href="#" id="btn" onclick="this.focus();return false">Click</a>
そしてCSS3コード
#btn {
background: yellow;
}
#btn:focus, #btn:active {
-webkit-animation: btn-color 1s forwards linear;
-moz-animation: btn-color 1s forwards linear;
-ms-animation: btn-color 1s forwards linear;
-o-animation: btn-color 1s forwards linear;
animation: btn-color 1s forwards linear;
}
@-webkit-keyframes btn-color { 0% { background: red; } 99% { background: red; } 100% { background: yellow; } }
@-moz-keyframes btn-color { 0% { background: red; } 99% { background: red; } 100% { background: yellow; } }
@-ms-keyframes btn-color { 0% { background: red; } 99% { background: red; } 100% { background: yellow; } }
@-o-keyframes btn-color { 0% { background: red; } 99% { background: red; } 100% { background: yellow; } }
@keyframes btn-color { 0% { background: red; } 99% { background: red; } 100% { background: yellow; } }