jQuery循环插件后的多个函数:选项

时间:2012-09-05 22:41:39

标签: jquery jquery-plugins jquery-cycle

所以这是我的周期声明:

function onAfter(curr, next, opts) {
    var index = opts.currSlide;
    $('.prev')[index == 0 ? 'hide' : 'show']();
    $('.next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
}

$(function() {
    $('#slideshow').cycle({
        pager:  '#nav',
        prev:   '.prev',
        next:   '.next',
        after:   onAfter,
    }).cycle('pause');
});

我希望在after:选项后添加活动类功能。我希望将这两个函数保留在:

之后

这是活动的类函数:

$('#slideshow').cycle({
    after: function(el, next_el) {
        $(next_el).addClass('active');
    },
    before: function(el) {
        $(el).removeClass('active');
    }
});

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

您可以通过将第二个函数添加到您的函数并使用适当的参数来组合这两个after函数:

function onAfter(curr, next, opts) {
    var index = opts.currSlide;
    $('.prev')[index == 0 ? 'hide' : 'show']();
    $('.next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
    $(next).addClass('active');
}