最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - carouFredSel add class to active slide - Stack Overflow

programmeradmin0浏览0评论

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 :)

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 :)

Share Improve this question asked Oct 27, 2013 at 3:19 veksenveksen 7,0035 gold badges22 silver badges33 bronze badges 1
  • I needed it on a button inside the slide... ended up binding a click event to that button with $active = $('#modeles .block:first-child');, #modeles being my carouFredSel wrapper, and .block being the slides. – veksen Commented Oct 27, 2013 at 4:48
Add a ment  | 

2 Answers 2

Reset to default 6

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

});

scroll : { onAfter : $highlight }

solved my issue

发布评论

评论列表(0)

  1. 暂无评论