Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Current slide in materialize css carousel

How to get current slide in materializecss carousel component? I don't know how to link from carousel content to active class in li tags.

For example i need get id element from div, where li class is active

like image 737
Rafał Gąsior Avatar asked Nov 16 '25 11:11

Rafał Gąsior


2 Answers

Use onCycleTo callback function option:

 $('.carousel').carousel({
    duration: 100,
    indicators: true,
    onCycleTo: function(data) {
      //do what needs to be done in here ...
   }
});

The data param returns the carousel-item active Link Element. You could pass parameters with a data-attribute for example.

like image 67
thooyork Avatar answered Nov 19 '25 10:11

thooyork


You can get the current slides index using onCycleTo. Adding this answer since the previous answers don't show what to do within the function. Here's an example to get you started:

$('.carousel').carousel({
    onCycleTo: function (ele) {
      console.log(ele);
      console.log($(ele).index()); // the slide's index
    }
});
like image 35
Pixelomo Avatar answered Nov 19 '25 11:11

Pixelomo