2

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

帮助!谢谢 :)

4

2 回答 2

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

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

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

});
于 2013-10-27T17:16:06.647 回答
0

滚动:{ onAfter :$highlight }

解决了我的问题

于 2015-03-10T06:25:23.333 回答