&を使用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; } }