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

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

救命! 谢谢 :)

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

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

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

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

scroll:{onAfter:$ highlight}

解决了我的问题