Problem with slider and the SetInterval

0

Good, I hope you can help me with this little problem

I'm trying to make a slider with jquery and js, it turns out that when you give the images a timer (setinterval) and its effect FadeOut and FadeIn, everything works perfect, but something happens that I think is wrong and can not be solved

It turns out that when I switch to the browser and stay out of the page where the slider is, when I return to the slider page, the images start to go by at an exaggerated speed as I try to show everything I do not he showed me during the time I was not present, and then he calms down and re-shoots the images with the normal speed, SOMEONE COULD HELP ME?

I'm currently just trying before starting the project and I do not want to deal with this

here is the link to look at (Ignore the order of the code, as it is only evidence)

link

    
asked by Miguel Esquivel Castrillo 03.05.2017 в 21:01
source

1 answer

0

I recommend you before assigning the ID in SliderInternal = setInterval(...) uses clearInterval .

Example:

var SliderInit = function() {
  if (SliderInternal)
    clearInterval(SliderInternal);

  SliderInternal = setInterval(function changeSlider() {
    sliderPanel.eq(CurrentSlider).fadeOut('slow');
    sliderPanel.eq(nextSlider).fadeIn('slow');

    //actualizar datos
    if (nextSlider >= lengthSlider - 1) {
      nextSlider = 0;
      CurrentSlider = lengthSlider - 1;
    } else {
      //actualizar datos
      CurrentSlider = nextSlider;
      nextSlider += 1;
    }
    //console.log(nextSlider);

  }, dataInterval);
};
    
answered by 03.05.2017 в 22:02