2011-05-26 65 views
2

我正在尋找使用slideToggle()自動每10秒左右一些divs。在下面的例子中,我希望SET 2到slideToggle()在10秒之後,10秒之後,我想SET 3到slideToggle(),之後10秒鐘,我想循環和slideToggle() SET 1回到(有點像旋轉木馬插件):jQuery simple setInterval to slideToggle

<style> 
    .ftdmfg2, .ftdmfg3 { 
     display:none; 
    } 
</style> 

<div align="center" id="featuredmfgs"> 
    <h2>Featured Manufacturers</h2> 
    <div class="ftdmfg1"> SET 1 </div> 
    <div class="ftdmfg1"> SET 1 </div> 
    <div class="ftdmfg1"> SET 1 </div> 
    <div class="ftdmfg1"> SET 1 </div> 
    <div class="ftdmfg2"> SET 2 </div> 
    <div class="ftdmfg2"> SET 2 </div> 
    <div class="ftdmfg2"> SET 2 </div> 
    <div class="ftdmfg2"> SET 2 </div> 
    <div class="ftdmfg3"> SET 3 </div> 
    <div class="ftdmfg3"> SET 3 </div> 
    <div class="ftdmfg3"> SET 3 </div> 
    <div class="ftdmfg3"> SET 3 </div> 
</div> 

回答

2

這個jQuery腳本應該做你想要的東西:

$(function() { 
var num = 1; 
var nummax = 3 
var toggletime = 10000; 
setTimeout(toggle, toggletime); 

function toggle() { 
    $('.ftdmfg'+num.toString()).slideToggle(); 
    num++; 
    if (num > nummax) num = 1; 
    $('.ftdmfg'+num.toString()).slideToggle(); 
    setTimeout(toggle, toggletime); 
} 

}

+0

這工作就像一個魅力謝謝你! – ToddN 2011-05-26 16:10:27

-1
function slideSet(setNum) { 
    //jquery slide 
    var nextSet = setNum +1; 
if(nextSet > 3) 
nextSet = 1; 

setTimeout(function() { slideSet(nextSet); }, 10000); 
}