.animation()
色をアニメーション化するには、jQuery UI もロードする必要があります。jQuery UI の関数はCSS の色名をサポートしていないことに注意してください。16 進値、 などを使用する必要がありrgb[a]()
ますhsl()
。
$(function () {
$('form :input').focus(function () {
$(this).closest('fieldset').stop(true,true).animate({
"background-color": "#808080" // CSS hex color equivalent of grey
},2000);
});
$('form :input').blur(function () {
$(this).closest('fieldset').stop(true,true)..animate({
"background-color": "transparent"
},2000);
});
});
注: .stop(true,true)
は.animate()
メソッドの前に使用され、ユーザーが入力にすばやくフォーカスしてぼかした場合に、アニメーション キューがスタックに終わらないようにします。
http://jsfiddle.net/teddyrised/8wRhG/
ただし、カラー アニメーションのためだけに jQuery UI をロードすることはお勧めしません。CSS トランジションを使用し、代わりに JS を使用してフィールドセットの背景を設定することをお勧めしますか?
$(function () {
$('form :input').focus(function () {
$(this).closest('fieldset').css({
"background-color": "#808080"
});
});
$('form :input').blur(function () {
$(this).closest('fieldset').css({
"background-color": "transparent"
});
});
});
CSS:
form fieldset input {
transition: background-color 2s linear;
}
http://jsfiddle.net/teddyrised/8wRhG/4/