여기 내 코드입니다. 내가 뭘 하려는지 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>
을 사용합니다. – marko
중복을 확인하려고합니까? '.MainNews'에 직접'$ .load()'를 사용하지 않는다면 같은 결과를 얻을 수 있습니까? – sjdaws