JSFiddle - React, Tailwind, and code Playground

by Roberto Apasajja

HTML

<span id='slideselector'></span>
<div id="slideshow">
   <div>
     <div class="imgLike" style="background-image: url('http://farm6.static.flickr.com/5224/5658667829_2bb7d42a9c_m.jpg'); background-position:center; "></div>
   </div>
   <div>
    <div class="imgLike" style="background-image: url('http://farm6.static.flickr.com/5230/5638093881_a791e4f819_m.jpg'); background-position:center; "></div>
   </div>
   <div>
       <div class="imgLike" style="background-image: url('http://gillespaquette.ca/images/stack-icon.png'); background-position:center; "></div>
   </div>
</div>

CSS

#slideselector {
    position: absolue;
    top:0;
    left:0;
    border: 2px solid black;
    padding-top: 1px;
}
.slidebutton {
    height: 21px;
	margin: 2px;
}
#slideshow { 
    margin: 50px auto; 
    position: relative; 
    width: 240px; 
    height: 240px; 
    padding: 10px; 
    box-shadow: 0 0 20px rgba(0,0,0,0.4); 
}

#slideshow > div { 
    position: absolute; 
    top: 10px; 
    left: 10px; 
    right: 10px; 
    bottom: 10px;
    overflow:hidden;
}

.imgLike {
    width:100%;
    height:100%;
}

JavaScript

$("#slideshow > div:gt(0)").hide();

function rotate(speed) { 
  $('#slideshow > div:first')
    .fadeOut(speed)
    .next()
    .fadeIn(speed)
    .end()
    .appendTo('#slideshow');
  $('input[name="slideselector"]')[$('#slideshow > div:first div.imgLike').attr('img-index')].checked=true;
};

function select(idx) {
    clearInterval(interval);
    $('#slideshow > div:first').fadeOut(1000)
    while ($('#slideshow > div:first .imgLike').attr('img-index') != idx) {
      rotate(0);
    }
    $('#slideshow > div:first').fadeIn(1000);    
    interval = setInterval(function(){rotate(1000);}, 3000);
}

$('.imgLike').each(function(i,el) {
    $(el).attr('img-index',i);
    $("<input>").attr({'id':'img-'+i, 'type':'radio', 'value':i, 'name':'slideselector'}).click(function() {select(i);}).appendTo($('#slideselector'))
});

var interval = setInterval(function(){rotate(1000);}, 3000);