2013-10-02 34 views
0

我向文件發送了一個post請求,並將其放入id ='balance',但我希望它閃爍或淡入,以便用戶知道它正在實時更新。我嘗試添加一個fadeIn(),但它沒有做我想做的事情。我做錯了還是有更好的方法?下面的代碼。jQuery淡入問題或替代

var balance_update = setInterval(function() { 
    $.post('./requests/balance.php', function(balance) { 
     $('#balance').html(balance).fadeIn(1000); 
    }); 
}, 400); 

回答

1

你可能只需要先隱藏起來,因爲fadeIn()不做任何可見的元素...需要隱藏

var balance_update = setInterval(function() { 
    $.post('./requests/balance.php', function(balance) { 
     $('#balance').html(balance).hide().fadeIn(1000); 
    }); 
}, 400); 
+0

永久隱藏它,並不會顯示在所有。 –

+0

有其他的東西導致它不顯示。如果你在這個頁面打開你的控制檯並輸入'$(「body」)。hide().fadeIn(1000)'你會看到頁面淡入。 – Archer

0

您元素的可見性。

使用CSS {display: none; }或jQuery的.hide方法wheb jQuery(document).ready();火災

0

這應該工作

$('#balance').html(balance).hide(function(){fadeIn(1000)});