jQuery动画运行一次

时间:2012-06-06 19:23:43

标签: javascript jquery jquery-animate

我有一个像这样的简单代码:

<input id="Button1" type="button" value="button" />    
<table border="1" cellpadding="0" cellspacing="0" width="400px">
    <tr id="tr1">
        <td>
            1
        </td>
        <td>
            nima
        </td>
    </tr>
    <tr id="tr2">
        <td>
            2
        </td>
        <td>
            agha
        </td>
    </tr>
    <tr id="tr3">
        <td>
            3
        </td>
        <td>
            ligha
        </td>
    </tr>
</table>

我为改变第一行背景写了这段代码

 $(document).ready(function () {
        $('#Button1').on('click', function () {
            $('#tr1').stop()
                     .animate({ backgroundColor: "aqua" },800)
                     .stop()
                     .animate({backgroundColor: "white"},800);
        });
    });

但它只运行一次,当我再次点击Button1时没有任何变化。问题出在哪里?

(我使用jQuery.Color插件) 感谢

1 个答案:

答案 0 :(得分:2)

$(document).ready(function () {
    $('#Button1').bind('click', function () {
       $('#tr1').animate({ backgroundColor: "aqua" },800)
             .animate({backgroundColor: "white"},800);
     });
});​

这适用于Google Chrome ...试试吧