Cycle through divs?

后端 未结 2 646
旧巷少年郎
旧巷少年郎 2021-01-07 06:08

I have this HTML:

first box
second box
相关标签:
2条回答
  • 2021-01-07 06:26
    $('a').click(function(){
        $('.boxes').filter(':visible').hide().next().add('.boxes:first').last().show();
    });
    
    0 讨论(0)
  • 2021-01-07 06:44
    $('a').click(function() {
        var visibleBox = $('#container .boxes:visible');
        visibleBox.hide();
        var nextToShow = $(visibleBox).next('.boxes:hidden');
        if (nextToShow.length > 0) {
            nextToShow.show();
        } else {
            $('#container .boxes:hidden:first').show();
        }
        return false;
    });
    

    Live demo.

    0 讨论(0)
提交回复
热议问题