2011-04-19 70 views
1

我想自动播放我的标签。自动播放标签

http://jsfiddle.net/w3father/KQN3z/

$('#tabs > a').click(function() { 
    var tab = $('.tab_' + $(this).attr('tab')); 
    if (tab.length) 
    { 
     // Hide active tab & selected style: 
     $('.tab_active').removeClass('tab_active'); 
     $('#tabs .active').removeClass('active'); 

     // Show clicked tab content 
     tab.addClass('tab_active'); 
     $(this).addClass('active'); 

     tab.show("slide", { direction: "down" }, 1000); 
     $(this).show("puff", {}, 10); 
    } 
}); 
+0

嗨伙计我有自己的想法http://jsfiddle.net/loganphp/4Z7pe.please做得好它有一些自动播放和用户点击的问题。你能帮我吗?/ – w3father 2011-04-20 10:13:55

回答

2
// starting index 
var currTab = 0; 

// count of all tabs 
var totalTabs = $("#tabs > a").length; 

// function to pass to setInterval 
function cycle() { 

    // simulate click on current tab 
    $("#tabs > a").eq(currTab).click(); 

    // increment counter 
    currTab++; 

    // reset if we're at the last one 
    if (currTab == totalTabs) { 
     currTab = 0; 
    } 
} 

// go! 
var i = setInterval(cycle, 1000); 

http://jsfiddle.net/karim79/KQN3z/5/

+0

它正在工作,但当我点击标签时它会崩溃。 – w3father 2011-04-19 11:10:44

+0

@ w3father - 我在这里改进了一点:http://jsfiddle.net/karim79/KQN3z/8/ – karim79 2011-04-19 11:25:20

+0

是的好。我觉得这是不正确的方式。我不知道如何做到这一点没有可折叠 – w3father 2011-04-19 11:33:53