carouFredSel将类添加到活动幻灯片中

vek*_*sen 2 javascript jquery caroufredsel

我正在尝试在carouFredSel的当前幻灯片中添加一类"active",我无法让它工作.我最接近它的工作是将它添加到第一张幻灯片上,使用trigger("currentVisible"),但它不会更新.

救命!谢谢 :)

use*_*308 6

到目前为止,我使用了这个函数(虽然它在页面加载时不起作用,但是对于那个简单的任务来说似乎是很多代码)也许有人知道如何简化这个并使它在页面加载时起作用

function highlight( items ) {
items.filter(":eq(1)").addClass("active");
}
function unhighlight( items ) {
items.removeClass("active");
}

$('#foo').carouFredSel({
scroll : {
onBefore: function( data ) {
  unhighlight( data.items.old );
},
onAfter : function( data ) {
  highlight( data.items.visible );
}
},
});
Run Code Online (Sandbox Code Playgroud)

这是一个应该在页面加载和滚动时工作正常的更新: 以下是有关触发事件的更多详细信息.

var $highlight = function() { 
    var $this = $("#foo");

    var items = $this.triggerHandler("currentVisible");     //get all visible items
    $this.children().removeClass("active");                 // remove all .active classes
    items.filter(":eq(1)").addClass("active");              // add .active class to n-th item
};


$('#foo').carouFredSel({

    scroll : {
        onAfter : $highlight
    },      
    onCreate    : $highlight

});
Run Code Online (Sandbox Code Playgroud)