0

I've created a Flickity slider through Jquery and require a little assitance. I'm using the selectedIndex as a condition to check what slider is visable. See code below:

    $carousel.on( 'select.flickity', function() {
    if (flkty.selectedIndex === 0) {
        hideAllText();
        text0.fadeIn('slow');
    }
});

This is saying, when slider 0 (initial slide) fade in var text0. I want to do this for 6 sliders but as the slide doesn't change until 4 seconds has been the if statement keeps running so it keeps hiding and showing text.

Any ideas how I can make this a one time run until the slide comes round again.

Thanks :)

Sam Ryan
  • 7
  • 5

1 Answers1

0

This should result in the relevant code only being executed once:

text0Shown = false;

$carousel.on('select.flickity', function() {
  if (!text0Shown && flkty.selectedIndex === 0) {
    text0Shown = true;
    hideAllText();
    text0.fadeIn('slow');
  }
});
Chris Satchell
  • 751
  • 5
  • 17