Slider Javascript Sumindo

Asked

Viewed 60 times

1

I wonder if you could help me. I am putting on the site that I am developing a very simple slider to just pass 3 images. the example I take on the site w3school. But as he goes through the images, by the time he arrives at the last he disappears and after a long time he returns. What will happen? Does anyone have any suggestions? Follow the code I’m using.

-- One problem I identified is that I’m trying to use 4 identical sliders on the same page, because when I took the other 3 the first one worked, what I do to use the 4 slider on the same page?

var myIndex = 0;
carousel();

function carousel() {
  var i;
  var x = document.getElementsByClassName("myCarousel2");
  for (i = 0; i < x.length; i++) {
    x[i].style.display = "none";
  }
  myIndex++;
  if (myIndex > x.length) {
    myIndex = 1
  }
  x[myIndex - 1].style.display = "block";
  setTimeout(carousel, 2000); // Change image every 2 seconds
}
<div class="w3-content w3-section">
  <img class="myCarousel2" src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150">
  <img class="myCarousel2" src="./img/efloor/gerencial_slider.png">
  <img class="myCarousel2" src="https://placeholdit.imgix.net/~text?txtsize=33&txt=300%C3%97150&w=350&h=150">
</div>
<!--Slider 2-->

  • Didn’t you make any changes to the code? I tested this code and it worked well.

  • Worse than not! I don’t understand why he’s doing this.

  • In your example up here is working normally, no?

  • Which browser you are using?

  • apparently this one. I’m using Mozilla and Chrome.

  • well I found out what happens, I’m trying to use 4 sliders of this on the same page, so I researched this giving conflict has to fix?

  • use the Opera and worked normal here

  • There is no error in the code, nor with 4 slides, take the example, didn’t understand the problem?

  • People thanks to everyone who tried to help, had a conflict with another script, at the time I removed the same all slides worked properly. Thank You All :)

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.