javascript - 使用动画颜色文本更改前置表格淡入?

标签 javascript jquery html css html-table

我有一张 table

function updateQueueTable(sessionName) {

    console.log("updateQueueTable executed ... ");

    var ajax = $.ajax({url: '/client-summary/' + sessionName + '/queue'});

    ajax.done(function (responses) {

        console.log('responses = ', responses);

        $('#queueTable').empty();

        for (i = 0; i < responses.length; i++) {

            let row = `
            <tr >
            <td>${responses[i].flow_type}</td>
            <td><a href="/client-summary/${responses[i].session_name }">${responses[i].session_name }</a></td>
            <td>${responses[i].vlan}</td>
            <td>${responses[i].source_ip}</td>
            <td>${responses[i].tunnel_endpoint}</td>
            <td>${responses[i].ue_mac}</td>
            <td>${responses[i].ue_type}</td>
            <td>${responses[i].action}</td>
            </tr>

            `;

            //**/console.log(row);

            $('#queueTable').prepend(row).fadeIn('slow').animate({ color: "#FFCD56" }, 1400).animate({ color: "white" }, 1400);
        }

    });
}

我可以看到前置发生,但淡入和颜色变化没有发生。

我做错了什么?


HTML

<table class="table table-responsive-sm">
    <thead>
        <tr>

            <th width="10%">Type</th>
            <th width="10%">Session Name</th>
            <th width="5%">VLAN</th>
            <th width="15%">Tunnel Source IP</th>
            <th width="15%">Tunnel Dest IP</th>
            <th width="15%">MAC Address</th>
            <th width="15%">Tunnel Type</th>
            <th width="15%">Action</th>

        </tr>
    </thead>
    <tbody id="queueTable">


        
    </tbody>
</table>

最佳答案

您将淡入淡出应用于表格而不是行。要将 fadein 应用于行,在您的情况下这不是 jquery 元素,行必须是 jquery 元素。代码应该如下所示:

for (i = 0; i < responses.length; i++) {

    let row = $('<tr style="display:none;">');

    let tds = `            
            <td>${responses[i].flow_type}</td>
            <td>
            <a href="/client-summary/${responses[i].session_name }">${responses[i].session_name }</a>
            </td>
            <td>${responses[i].vlan}</td>
            <td>${responses[i].source_ip}</td>
            <td>${responses[i].tunnel_endpoint}</td>
            <td>${responses[i].ue_mac}</td>
            <td>${responses[i].ue_type}</td>
            <td>${responses[i].action}</td>
            `;
    row.html(tds);

    //**/console.log(row);

    $('#queueTable').append(row);
    row.fadeIn('slow').animate({
      color: "#FFCD56"
    }, 1400).animate({
      color: "white"
    }, 1400);
  }

Here is a working fiddle供使用假数据引用。

关于javascript - 使用动画颜色文本更改前置表格淡入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57101002/

相关文章:

java - 如何仅从 HTML 页面中提取主要文本内容?

javascript - Element.style.left 属性拒绝取值?

php - 在 PHP 中解析 Javascript 文件以提取其中定义的数组的最佳方法

javascript - javascript 递归太多

javascript - 在 .on ('click' ) 事件处理程序中传递函数和函数参数?

javascript - 谷歌浏览器扩展程序: Alert when Modal/popup closed

javascript - 如何只允许滚动条滚动

javascript - 使用 Babel 6 在 Azure 上自定义 Node.js 应用程序的启动命令

javascript - 如何使用 Javascript 获取继承的 CSS 值?

javascript - 如何使用 Kendo UI Grid 的 SetDataSource 方法