3

I have a slider and it's automatically changing the contents.

<div class="main-slider">
  <div class="slide slide-active" data-num="1"> <img> </div>
  <div class="slide"  data-num="1"> <img> </div>
  <div class="slide" data-num="2"> <img> </div>
  <div class="slide"  data-num="3"> <img> </div>
</div>

Here when slider is working this slide-active class is automatically changed to next slide .

What I need is, I need to trigger an event when slide active class is changed . For example I need to alert the corresponding data-num value of active slide.

How I can do this ?

Abilash Erikson
  • 341
  • 4
  • 26
  • 55

2 Answers2

1

Since you are using FlexSlider refer the original documentation. It has an event called after which will fire when a slide gets animated.

$(".main-slider").flexslider({
  after: function(){
     alert($(".slide-active:eq(0)").attr("data-num"));
  }
});

Hope this might helps...

Read more about here https://github.com/woocommerce/FlexSlider/wiki/FlexSlider-Properties

Thusitha
  • 3,393
  • 3
  • 21
  • 33
-1

if id didn't get it wrong your code already moves slide-active class to the next slide, right? so for making the slider you need a for loop and you set var i and add one to it each time. ( start from 0 index num untill your slide class number ) you should add the alert event in the for loop so when ever slide changed it triggers alert.

this might be a little confusing so plz add your JS code so i can help u better

good luck

Mohammad Moallemi
  • 628
  • 1
  • 5
  • 13