【问题标题】:jQuery Cycle plugin "before" event not working?jQuery Cycle 插件“之前”事件不起作用?
【发布时间】:2012-02-12 03:33:24
【问题描述】:

我正在使用 jQuery Cycle 插件。

我在幻灯片下方有一个“当前#/总#”计数器类型的东西。每次转换后我都会更新“当前#”。 我成功地使用了“after”回调事件,但“before”事件似乎不适用于第一次转换。我希望当前的 # 更改 before 幻灯片图像过渡到下一个,而不是 after 过渡。 以前有人遇到过这个问题吗?

我有以下代码:

slideshow.cycle({ 
    timeout: 6000,
    next: '#nextImage', 
    prev: '#prevImage',
    after: setCurrent
});

function setCurrent(curr,next,opts) {
    $('#imageNumber').html(opts.currSlide + 1);
}

[编辑]

我可以使用以下代码解决此问题:

slideshow.cycle({ 
    timeout: 6000,
    next: '#nextImage', 
    prev: '#prevImage',
    before: setCurrent
});

function setCurrent() {
    var image = $(this);
    $('#imageNumber').html(image.index() + 1);
}

【问题讨论】:

    标签: jquery events plugins cycle


    【解决方案1】:

    'before'/'after' 回调方法不带参数。在方法的上下文中(即您的 setCurrent),您可以使用 'this' 作为要呈现的项目。

    参考:http://jquery.malsup.com/cycle/int2.html

    所以你需要做一些类似的事情:

    function setCurrent() {
      $('#imageNumber').html(this.id + 1);
    }
    

    注意:我不知道您的其余代码,因此您可能需要适应...

    【讨论】:

    • 您的回答帮助我发现了如何解决它。我将在下面发布我的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-23
    • 1970-01-01
    • 2012-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-21
    相关资源
    最近更新 更多