JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div class="preview-slider">
<button class="slider-btn slider-btn-prev"><</button>
<button class="slider-btn slider-btn-next">></button>
<ul class="slides">
<li class="slide active"><img src="http://lorempixel.com/400/200" /></li>
<li class="slide"><img src="http://lorempixel.com/400/200/sports" /></li>
<li class="slide"><img src="http://lorempixel.com/400/200/sports/1" /></li>
</ul>
</div>
CSS
.slide img{
max-width:100%;
max-height:100%;
position: relative;
}
.slide {
display: none;
width: 100%;
height: 100%
}
.slide.active {
display: block;
}
.slides{
list-style-type: none;
}
JavaScript
(function ($) {
var SliderWidget = function (element, settings) {
function _SliderWidget(element, settings) {
this.config = {
hasBullets: false,
hasThumbnails: false,
$thumbnails: null
};
$.extend(this.config, settings);
this.initials = {
$thumbnails: null,
$pictures: {},
$bntNext: {},
$btnPrev: {},
$bullets: {},
total: 0,
currentIndex: 0
};
$.extend(this, this.initials);
this.$el = $(element);
this.setup();
};
return _SliderWidget;
}();
SliderWidget.prototype.setup = function () {
this.$pictures = this.$el.find(".slide");
this.$btnNext = this.$el.find(".slider-btn-next");
this.$btnPrev = this.$el.find(".slider-btn-prev");
if (this.config.$thumbnails !== null) {
this.$thumbnails = this.config.$thumbnails.find(".own-thumbnail");
this.$thumbnails.click($.proxy(function (event) {
this.currentIndex = $(event.currentTarget).index();
this.cycleItems();
}, this));
}
this.$btnNext.click($.proxy(function () {
this.updateIndex(1);
this.cycleItems();
}, this));
this.$btnPrev.click($.proxy(function () {
this.updateIndex(-1);
this.cycleItems();
}, this));
this.total = this.$pictures.length;
if (this.config.hasBullets) {
var $previewSlider = this.$el.find(".preview-slider");
$previewSlider.append("<div class='bullets'>");
for (var i = 0; i < this.total; i++) {
$previewSlider.append("<span class='bullet'>test</span>");
}
$previewSlider.append("</div>");
this.$bullets = $(".bullet-" + this.config.sliderNumber);
}
};
SliderWidget.prototype.updateIndex = function (increment) {
this.currentIndex += increment;
if (this.currentIndex > this.total - 1) {
this.currentIndex = 0;
} else if (this.currentIndex < 0) {
this.currentIndex = this.total - 1;
}
};
SliderWidget.prototype.cycleItems = function () {
var $picture = this.$pictures.eq(this.currentIndex);
if (this.$thumbnails !== null) {
var...