I have an extremely primitive slider using fadeIn, fadeOut and some control bullets.
https://jsfiddle.net/c2dsnr8v/1/
<div class="view">
<ul class="list">
<li class="frst">
<img src="http://www.guessthelogo.com/wp-content/uploads/2012/11/random-dice.gif" />
</li>
<li class="scnd">
<img src="https://avatars.yandex.net/get-music-content/a19fc9b4.a.1767585-1/200x200" />
</li>
<li class="thrd">
<img src="http://randomacts.channel4.com/images/fb_logo.gif" />
</li>
<li class="frth">
<img src="http://cs620120.vk.me/v620120530/93f0/k7U9HGQOBkw.jpg" />
</li>
</ul>
<div class="ctrl">
<div class="bullet one"></div>
<div class="bullet two"></div>
<div class="bullet three"></div>
<div class="bullet four"></div>
</div>
</div>
$(".list li:gt(0)").hide();
var int = setInterval(function(){
$('.list > :first-child')
.fadeOut()
.next()
.fadeIn()
.end()
.appendTo('.list');} ,3000);
$(".bullet").on("click", function(){
clearInterval(int);
$(".list li").fadeOut();
var $this = $(this);
if($this.hasClass("one")){
$(".list li.frst").fadeIn();
}else if($this.hasClass("two")){
$(".list li.scnd").fadeIn();
}else if($this.hasClass("three")){
$(".list li.thrd").fadeIn();
}else if($this.hasClass("four")){
$(".list li.frth").fadeIn();
}
})
I figured out how I can make pictures appear on clicking bullets (green squares), and the setInterval function here is clear enough. But when I tried to join these mechanisms together, I found out that I can only clear setInterval with a click. So once I use bullets, automatic rotating doesn't work anymore.
Is there any way to join the two together, using this code? For example, I click on a bullet, the picture stands still for 5 seconds, and then it keeps rotating further with the same speed?
I tried to include a new setInterval after each bullet click, but failed.
Here is an updated snippet that removes the jumpiness. Basically the issue was in the ".appendTo('.list');", which reordered the list items and made it difficult to continue the rotation once a bullet was clicked. The code significantly changed to get around this, but it should be more efficient since the dom isn't being reordered every time through. Also, I removed a bunch of unnecessary classes and and am now using .index() to coordinate between the bullets and list items, as mentioned previously.