這是我的代碼。我想要做的是使用jQuery在我的頁面更新新聞。該代碼按預期工作 - 每隔5秒鐘從側邊欄刪除新聞並在他們的位置發佈2個更新。我不能做的是在發佈更新之前刪除所有消息。現在它追加更新並同時開始淡出舊消息。 任何人有想法如何設置適當的超時這個?jQuery超時功能內
function updateNews()
{
$('.newsUpdate').load('news.html .news', function()
{
$('.MainNews').fadeOut(); /* timeout should happen here! */
var start = Math.floor(Math.random() * 4);
var stop = start + 2;
$(this).children('.news').slice(start, stop).css('display', 'none').attr('class', 'MainNews').insertAfter('.nav').fadeIn().children('span').remove();
$(this).children('.news').remove();
});
setTimeout(updateNews, 5000);
}
updateNews();
HTML很簡單:
<div class='sidebar'>
<ul class='nav'>
<li></li>
</ul>
</div>
<article>main content of the site</article>
<div class='newsUpdate'>this created specially to upload news from news.html and manipulate them</div>
顯示HTML那就更清楚你要完成的任務。 – marko 2013-02-24 09:06:54
你想檢查重複嗎?如果不是不會直接在'.MainNews'中使用'$ .load()'實現相同的結果? – sjdaws 2013-02-24 09:35:11