JSFiddle - React, Tailwind, and code Playground

by tmyie

HTML

<div class="module m-slide">
    <img src="http://placehold.it/1200x800&text=1" alt="" />
    <img src="http://placehold.it/1200x800&text=2" alt="" />
    <img src="http://placehold.it/1200x800&text=3" alt="" />
    <div class="m-slide-ctrl"></div>
</div>

CSS

img {
    max-width: 100%;
}
.module {
    width: 350px;
    position: relative;
}
.m-slide img {
    display: none;
}
img.active {
    display: block;
}
.m-slide-ctrl {
    position: absolute;
    bottom: 15px;
    right: 15px;
    z-index: 10;
}
.dot {
    width: 15px;
    height: 15px;
    background-color: #000;
    border-radius: 15px;
    display: inline-block;
    margin: 0 2px;
}
.dot:hover {
    opacity: 0.3;
}

JavaScript

var dot = '<div class="dot"></div>';
var number = $('.m-slide img').length;
var img = $('.m-slide img');

// slideshow


img.first().addClass('active');



img.click(function () {
    
    
    if ($('.m-slide img:last').is('.active')) {  
        $(this).removeClass('active');
       img.first().addClass('active');
    } else {
        $(this).removeClass('active').next('img').addClass('active');
    }

});



for (i = 0; i < number; i++) {
    if (number > 1) {
        $(dot).appendTo('.m-slide-ctrl');
    }
}


$('.dot').click(function () {
    $(this).hide();
});