jQuery empty()/remove()使页面跳转 [英] jQuery empty()/remove() makes page jump
问题描述
我有一个监视网站,显示谁登录"及其状态"(在线/离开/等).
I have a monitoring website which shows "who is logged in" and their "state" (online/away/etc.).
它们基本上被包裹在我页面的底部,并带有:
They are basically wrapped near the bottom of my page with:
<table cellpadding="0" cellspacing="0" id="telecaster_agentenstatus" class="telecaster">
<tr>
<td id="free_agents">
</td>
<td id="acw_agents">
</td>
<td id="pause_agents">
</td>
</tr>
<tr id="telecaster_agentenstatus_start">
<td id="agentenstatuus" colspan="3">
<div class="agent_telecaster_container"></div>
</td>
</tr>
</table>
因此,所有代理"都以"agent_telecaster_container"类进入div. 我可以根据需要添加任意数量的div:
So all "agents" get into the div with the class "agent_telecaster_container". I append as many divs as I need with:
for (nameAgent in supervisionagents.group[0].agent) {
//$("#agentenstatuus").append('<div class="agent_telecaster">'+nameAgent+'</div>');
counter++;
if (supervisionagents.group[0].agent[nameAgent].stateCurrent.description == "idle")
{
$(".agent_telecaster_container").append('<div id="agent'+counter+'" class="agent_telecaster"><img src="images/icons/box_green_12x12.png"> ' + nameAgent + '</div>');
}
一遍又一遍被叫
我需要的是清除"其内容,因为这可能是每秒钟有人离线或在线.
What I need is to "clear" the with its content because it can be that every second someone gets offline or online.
到目前为止,这很简单:
So far this can be possible with a simple:
$('.agent_telecaster_container').empty() / .remove();
但是随后发生的是,如果我移动视图/滚动条以查看该表下方的某些内容,则每次重新加载(每秒)时,它都会跳回到this. 我猜这是由于remove/empty而发生的,并且此元素被删除了,但是新内容进入了.
But what then happens is that if I move my view / scrollbar to view some things underneath that table, with every reload (every sec.) it jumps back to this . I guess this happens because of the remove / empty and this element gets deleted but new content gets in.
有人对如何防止跳跃有任何想法吗? :/
Has anybody any idea on how to prevent the jumping? :/
推荐答案
您是否尝试过先隐藏元素然后将其删除? .hide().remove();或尝试一下fadeOut(),然后在回调中调用remove():
Have you tried hiding the element first, and then removing it? .hide().remove(); Or try a fadeOut() then call remove() in the callback:
.fadeOut('fast',function( $('.agent_telecaster_container').remove(); ));
这篇关于jQuery empty()/remove()使页面跳转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!