2011-09-20 57 views
0

我使用下面的jQuery腳本進行幻燈片演示。我遇到的問題是,頁面最初加載時會短暫閃爍隊列中的下一張幻燈片。我怎樣才能防止這種情況發生?我的代碼來自這裏:http://snook.ca/archives/javascript/simplest-jquery-slideshowjQuery幻燈片顯示頁面加載時的其他幻燈片?

jQuery('#welcome div:gt(0)').hide(); 
setInterval(function(){ 
    jQuery('#welcome :first').hide() 
     .next('.slidey').fadeIn() 
     .end().appendTo('#welcome');}, 
    5000); 


<script src="scripts.js"></script> 

<div id="welcome"> 

<div class="slidey"> 
    <h1>Example.com</h1> 
    <br /> 
    <a href="http://www.example.com/about">Learn More</a> 
</div> 

<div class="slidey"> 

    <h1>The best widgets in the world...</h1> 

    <br /> 

    <a href="http://www.example.com/buywidget">Buy Widget</a> 

</div> 

一切,我決定改用這個幻燈片代碼:http://www.webchief.co.uk/blog/simple-jquery-slideshow/index.php它有更多的功能...

回答

0

你嘗試加入的功能document.ready? (http://api.jquery.com/ready/)

$(document).ready([your functions]) 

編輯如果你想隱藏的div使用CSS

style="display:none"> 
+0

是的,我目前有這個。 –

+0

哦..你的意思是其他的div是這樣的..首先顯示,直到腳本啓動? - >請參閱編輯:首先隱藏divs –

0

上你forrst?我看到此發佈更早:

jQuery(function($) { 
    $('#welcome div:gt(0)').hide(); 
    setInterval(function(){ 
     $('#welcome :first').hide() 
      .next('.slidey').fadeIn() 
      .end().appendTo('#welcome'); 
    }, 5000); 
}); 
+0

不,我不是Forrst –

+0

在這種情況下,它看起來像是不正確的使用'.end()',我不太瞭解它,只是讀一點,看到一個例子,但不是每次只追加第一個元素? – daryl

+0

我的代碼來自這裏:http://snook.ca/archives/javascript/simplest-jquery-slideshow –