简体   繁体   English

如何使用jQuery使TD正确滑动

[英]How to make TDs slide right with Jquery

I have this 我有这个

function loadActivity() {
    $.ajax({ url: "default.aspx?onemore=yes", dataType: 'json', context: document.body, type: "POST",
        success: function (data) { if (data == null || data == '') loadActivity(); addActivity(data.msg, data.logo, data.bag, data.date); }
    });
}

function addActivity(msg, logo, bag, date) {
    $("#activities tr:nth-child(2) td:last-child").fadeOut(2500, function () { $(this).remove(); appendNewAct(msg, logo, bag, date) });

}
function appendNewAct(msg, logo, bag, date) {
    $("#activities tr:nth-child(2)").prepend('<td style="display: none;" class="activity"><img class="bag" src="images/' + bag + '.png" /><div>' + msg + '</div><div class="time">' + date + '</div>' + (logo != '' ? '<img class="logo" src="' + logo + '" />' : '') + '</td>');
    $("#activities tr:nth-child(2) td:first-child").fadeIn(2500, function () { setTimeout(loadActivity, 2500); });
}

As you can see, I have table with TDs side by side. 正如你所看到的,我有TD并排的桌子。 The script is removing each 2.5seconds a right TD and places a new TD on the left. 该脚本正在移除每个2.5秒的右TD并在左侧放置一个新的TD。 My problem is, when removing the right TD (using the fadeOut) -> all the left TDs are jumping and replacing its place. 我的问题是,当删除右边的TD(使用fadeOut) - >所有左边的TD都在跳跃并替换它的位置。 I want them to slide smoothly to the right, like a activity stream. 我希望他们像活动流一样平稳地向右滑动。

<table cellspacing="0" cellpadding="0" id="activities">
                <tbody>
                <tr><td class="activity" style="">blblblblblb
                <td>
<td class="activity" style="">lblblblblb
                <td>
<td class="activity" style="">lblblblblb
                <td>
<td class="activity" style="">blblblbl
                <td></tr>
</tbody></table>

Thanks 谢谢

Table cells are not the right tool in this case; 在这种情况下,表格单元格不是正确的工具; the table will go to great lengths to occupy all it's area and laying out the cells is not a simple task. 桌子会竭尽全力占据所有区域,布置单元格并不是一件容易的事。

Try to achieve the effect using DIV s with display: inline; 尝试使用带display: inline; DIV实现效果display: inline; style. 样式。

I would look into jQuery's animate function and use it on the css attributes left and right. 我将研究jQuery的animate函数,并将其用于左右css属性。

http://api.jquery.com/animate/ http://api.jquery.com/animate/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM