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

时间:2013-10-27 03:19:53

标签: javascript jquery caroufredsel

我试图添加一个"活跃的"在carouFredSel的当前幻灯片中,我无法让它工作。最接近我可以使用trigger("currentVisible")将其添加到第一张幻灯片上,但它没有更新。

帮助!谢谢:))

2 个答案:

答案 0 :(得分: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 );
}
},
});

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

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

});

答案 1 :(得分:0)

滚动:{         onAfter:$亮点     }

解决了我的问题