carouFredSel add class to active slide

流过昼夜 提交于 2019-12-12 21:12:44

问题


I'm trying to add a class of "active" to the current slide in carouFredSel, and I can't get it to work. The closest I could get it to work was to add it on the first slide, using trigger("currentVisible"), but it doesn't update.

Help! Thanks :)


回答1:


So far, I used this function ( it doesn't work on page load though and it seems to be a lot of code for that simple task) Maybe someone has an idea how to simplify this and also make it work on page load

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's an update that should work fine on page load and scroll: Here are more details about the trigger event.

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

});



回答2:


scroll : { onAfter : $highlight }

solved my issue



来源:https://stackoverflow.com/questions/19614266/caroufredsel-add-class-to-active-slide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!