0

要素が更新されたときに要素の背景色を変更しようとしています。

サーバーから応答が返ってきたら、要素の背景色を 1 秒ほど変更してから、元に戻します。背景色は変更できますが、同じ呼び出しで元に戻すことはできません。

これが私がこれまでに持っているものです:

$.each(theArray,function(intIndex,objValue){
    $("#" + objValue.id).parent().css('background-color','red');
});
//NEED TIMING EVENT FOR DELAY 
$.each(theArray,function(intIndex,objValue){
    $("#" + objValue.id).parent().css('background-color','transparent');
});

最初のループは正常に動作しますが、他のループを動作させることができません。

私はこのようにしてみました:

$.each(theArray,function(intIndex,objValue){
     $("#" + objValue.id).parent.css('background-color','red').delay(1000).css('background-color','transparent');
});

それも何もしませんでした。

そのため、何が問題なのかよくわかりません。助言がありますか?

4

4 に答える 4

4
$.each(theArray,function(intIndex,objValue){
    var $el = $("#" + objValue.id).parent().css('background-color','red');
    setTimeout(function(){
        $el.css('background-color', '');
    }, 1000);
});

ここにデモがあります:http://jsfiddle.net/Wnntu/

于 2012-04-16T17:57:11.050 に答える
0

おそらくもっと探しているでしょう.css('background-color','')。これにより要素スタイルから削除されるため、チェーンの最後のスタイルが適用されます。しかし、透明が機能しない理由がわかりません。

アップデート、

ここを参照してください: http://jsfiddle.net/

于 2012-04-16T17:56:38.300 に答える
0

これを試して:

$.each(theArray,function(intIndex,objValue){
    $("#" + objValue.id).parent().css('background-color','red').delay(1000).queue(function() {
        $(this).css('background-color','');
        $(this).dequeue();
    });
});
于 2012-04-16T17:56:41.033 に答える
0

.delay()アニメーション効果キューまたはカスタム キューでのみ機能し、jQuery UI を使用しないアニメーションは色で機能しません...

setTimeout()代わりに、次の呼び出しを使用できます。

$.each(theArray,function(intIndex,objValue){
    var myObj = $("#" + objValue.id).parent().css('background-color','red');
    setTimeout(function() {
        myObj.css('background-color','transparent');
    },1000);
});
于 2012-04-16T17:57:00.957 に答える