自动播放标签页

时间:2011-04-19 10:46:48

标签: javascript jquery jquery-ui

我希望自动播放我的标签。

请检查

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);
    }
});

1 个答案:

答案 0 :(得分: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/