在填充后,我的数据行上有一些jquery和css条带化(动画)

时间:2013-11-04 18:34:48

标签: jquery css jquery-animate

在点击之前它们看起来像这样:

Before any click has occurred

单击业务范围中的“销售”时,会出现一个下拉选择框。如果我点击“销售”并对该文本区域进行更改,则会将其设置为灰色。灰色的行也是灰色的,这很好,但是黑色行应该淡化为黑色而不是灰色。

选择完毕后:

enter image description here

注意我将Sales更改为属性,在animate()函数之后,它变为灰色并且现在搞砸了条带化。

这是我的功能:

success: function (result) {
                    if (result) {
                        //change the verbiage of the ".look" element to the newly-changed value of the ".touch" element
                        theLook.text(newDes);

                        //swap out the elements so it looks like a normal table cell again
                        back_to_look();

                        //flash the span it's in so the user knows the change was successful
                        theTd.css('background-color','#59b4d4').animate({ backgroundColor: "#333333" }, 1500);
                    } else {
                        //flash the ".touch" element in red but DO NOT flip back to the ".look" element since there was a problem updating the data
                        var oldColor = theTouch.css('background-color');
                        theTouch.css('background-color','#ff0000').animate({ backgroundColor: oldColor }, 1500);

如何确定原始背景颜色设置,然后返回 它呢?我是否必须使用jquery css()方法来定位css?

2 个答案:

答案 0 :(得分:1)

这一行:

theTd.css('background-color','#59b4d4').animate({ backgroundColor: "#333333" }, 1500);

使用闪光灯(高亮显示)完成后,将bg颜色更改回#333333 ..试试这个:

var currentColor = theTd.css('backgroundColor');
theTd.css('background-color','#59b4d4').animate({ backgroundColor: currentColor }, 1500);

所以,不是像之前一样在动画中分配backgroundColor:#333333,而是创建一个名为currentColor的变量,并从我们即将编辑的表格单元格中拉出当前背景颜色。

这样,一旦我们编辑了表格单元格,我们就知道它需要返回哪种颜色。您可以在上面的第二行中看到,而不是将其设置回#333333,我们将其设置为我们的新变量currentColor。

答案 1 :(得分:0)

要确定背景颜色,请执行以下操作:

$(document).on('click', 'div', function () {
    var x = $(this).css('background-color');
    hexColor(x);
    alert(color);
});

function hexColor(colorValue) {
    var parts = colorValue.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
    delete(parts[0]);
    for (var i = 1; i <= 3; ++i) {
        parts[i] = parseInt(parts[i], 10).toString(16);
        if (parts[i].length == 1) parts[i] = '0' + parts[i];
    }
    color = '#' + parts.join('');
}

Example online