开发者

how to highlight tables first row for 2 seconds and get back to original state

I have a table in where once i add a row, its background color changes to show the changes (highlight will be good). Here is what i am doing

$("#tableDg tbody tr:first").css("background-color", "red")

So in order for the delay to work i did

$("#tableDg tbody tr:first").css("backgrou开发者_运维知识库nd-color", "red").delay(2000).css("background-color", "aqua");

but instead of delaying it just paints the bkg color to aqua, any comments what can i do here? Thanks


$("#tableDg tbody tr:first").css("background-color", "red");

setTimeout(function() {
    $("#tableDg tbody tr:first").css("background-color", "aqua");
}, 2000);

To Add the highlight effect:

$("#tableDg tbody tr:first").css("background-color", "red");

setTimeout(function() {
    $("#tableDg tbody tr:first").css("background-color", "aqua").effect("highlight", {}, 3000);
}, 2000);

Or this:

$("#tableDg tbody tr:first").css("background-color", "red");

setTimeout(function() {
    $("#tableDg tbody tr:first").css("background-color", "aqua");
    $('#tableDg tbody tr:first').effect("highlight", {}, 3000);
}, 2000);


Maybe this will help: I added a data attribute to the row to highlight the one I want, so I named it data-id.

  1. Get the original background color
  2. Animate to the highlight color
  3. wait 500 miliseconds
  4. Animate to the original color (fade out)
  5. Remove the style so the stylesheet can make its work.

    var highlight_color = "#fbec88";
    var original_color = $('#myTable tbody tr[data-id="' + id + '"]').css("background-color");
    
    $('#myTable tbody tr[data-id="' + id + '"]')
    .animate({
    'background-color': highlight_color
    }, 'slow', 'swing')
    .delay(500)
    .animate({
    'background-color': original_color
    }, 'slow', 'swing', function () { 
                        $('#myTable tbody tr[data-id="' + id + '"]').removeAttr("style"); 
                    });
    


If you need a single delay you should use setTimeout(function(){//code}, timeout);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜