JavaScript carouFredSel add class to active slide

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

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

});
Answer:2

I am using the following script to change the HTML5 required attribute of my input elements. I am wonder whether there is a way to modify this script to make it also work in Safari browsers, since ...

I am using the following script to change the HTML5 required attribute of my input elements. I am wonder whether there is a way to modify this script to make it also work in Safari browsers, since ...

  1. javascript html5 required attribute
  2. javascript html5 required
  3. html5 required javascript submit

This seems like it should work but doesn't. I'm not sure where the problem is - either I'm doing it wrong, or it's possible I have a syntax error. I just doesn't do anything. I'm trying to get the ...

This seems like it should work but doesn't. I'm not sure where the problem is - either I'm doing it wrong, or it's possible I have a syntax error. I just doesn't do anything. I'm trying to get the ...

  1. change image when hover
  2. change image when clicked
  3. change image when button is clicked android
  4. change image when button is clicked
  5. change image when scroll
  6. change image when clicked css
  7. change image when clicked android
  8. change image when hover javascript
  9. change image when mouse over
  10. change image when click jquery
  11. change image when mouse hover css
  12. change image when hover jquery
  13. change image when mouseover javascript
  14. image change when
  15. change image on button click javascript
  16. change image on hover codepen
  17. change image on linkedin post
  18. change image on mouseover
  19. change image on scroll jquery
  20. change image on hover css w3schools

Currently I have a Javascript function that uses I can hard code values in like - data: [1,4,7,9] However I wish to pass in an integer list to set the values from the code behind something like - C#...

Currently I have a Javascript function that uses I can hard code values in like - data: [1,4,7,9] However I wish to pass in an integer list to set the values from the code behind something like - C#...

I want to sort my table data in expandable table view, so I tried the below code: Code Link and my view is as in the below image When I use this code and put in my site, it is not working in this ...

I want to sort my table data in expandable table view, so I tried the below code: Code Link and my view is as in the below image When I use this code and put in my site, it is not working in this ...