Jquery:找一个表行,淡出然后淡入

时间:2012-08-24 09:33:27

标签: jquery

function fncFadeRowIntoTable(pTable,pColumn,pValue, pHtml) {
// Add a row to a table in the correct place, by comparing the contents of the column passed (starts 0).
// This assumes that the table is already sorted
var counter = 0; // so we know when we've reached the end
//
pValue = rtrim(pValue);

$('#'+pTable).find('tbody tr').each(function() {
    counter++;
    if (rtrim($(this).find('td:eq('+pColumn+')').attr('id')) == pValue) { 
    //  Have we found a cell equal to the the value passed. If so, then remove the row and replace
        var $wsRow = $(pHtml);
        $wsRow.hide();
        $(this).fadeOut(1000,function() { 
            $wsRow.insertAfter($(this)).hide();
            $(this).remove();
            $wsRow.fadeIn(1000).css('display', 'table-row');
        });
        return false; // break out of each() since we're done
    }
    if (rtrim($(this).find('td:eq('+pColumn+')').attr('id')) >= pValue) { 
    //  Have we found a cell greater than the value passed
        var $wsRow = $(pHtml);
        $wsRow.hide();
        $(this).before($wsRow);
        $wsRow.fadeIn(1000).css('display', 'table-row');
        return false; // break out of each() since we're done
    }
    // Handle case where we've reached the end, but we're still in the loop.
    // This means the new row is alphabetically last, so insert after
    if ($(this).closest('#'+pTable).find('tbody tr').length === counter ) {
        var $wsRow = $(pHtml);
        $wsRow.hide();
        $(this).after($wsRow);
        $wsRow.fadeIn(1000).css('display', 'table-row');
    }
});
// Handle empty table;
if ($('#'+pTable).find('tbody tr').size() == 0) {
        var $wsRow = $(pHtml);
        $wsRow.hide();
        $wsRow.appendTo('#'+pTable+' tbody');
        $wsRow.fadeIn(1000).css('display', 'table-row');
}
}

我有一个函数,我用它来更新表中的行,基于匹配单元格的内容。它将插入一个新行,或更新现有行。

上面的部分会替换匹配的行。我想要实现的是现有行首先淡出,然后新行淡入。

我得到的是新行立即可见,然后旧行逐渐淡出。 .hide()似乎没有效果,但是,我知道.hide()在插入行时正在工作。

我已经分别尝试过.hide()了     $ wsRow.hide(); 还有:     $ wsRow.insertAfter($(本))隐藏()。 或如上所示,在两个地方。

任何想法,我做错了,请。

注意:
pHtml是一个完整的行;即“tr ... / tr”数据。

1 个答案:

答案 0 :(得分:0)

您的代码适用于Chrome和IE8,现有行淡出然后新行淡入 - http://jsfiddle.net/x3JYz/1/

你有其他可能干扰的代码吗?