JSFiddle - React, Tailwind, and code Playground

by Alin Guta

HTML

<div id="poster-slider">
    
    <div href="#" class="gallery_controls-prev">prev</div>
    <div href="#" class="gallery_controls-next">next</div>
    
    <div class="gallery-wrap">
        <div class="gallery clear">
            <div class="gallery_item">
                <img src="img/afis_small.jpg" class="gallery_img" alt="" />
            </div>
            <div class="gallery_item">
                <img src="img/afis_small.jpg" class="gallery_img" alt="" />
            </div>
            <div class="gallery_item">
                <img src="img/afis_small.jpg" class="gallery_img" alt="" />
            </div>
        </div>
    </div>
</div>

CSS

#poster-slider {
    height:250px;
    width:400px;

}
.gallery-wrap {
    margin: 0 auto;
    overflow: hidden;
    height:250px;
    width:400px;
    z-index:100;
    position:relative;
}
.gallery {
    position: relative;
    left: 0;
    top: 0;
}
.gallery_item {
    float: left;
    list-style: none;
    display:table;
    position:relative;
    z-index:100;
}
.gallery_img {
    display: table;
    height:250px;
    width:400px;
}
/*
.gallery:hover > div {
  opacity: 0.5;
}
.gallery:hover > div:hover {
  opacity: 1.0;
}
*/

/*
.gallery_img {
	display: table;
	height: 290px;
	margin:0 10px;
	width:202px;
	padding:40px 14px 0 14px;
}
.active-item .gallery_img{
	cursor:default;
	padding:0 !important;
	height:330px !important;
	width:230px !important;
}
*/
 .gallery_controls-prev, .gallery_controls-next {
    cursor: pointer;
    width:auto;
    height:auto;
    display:table
    z-index:500 !important;
    position:absolute;
    bottom:10px;
    left:10px;
}
.gallery_controls-next {
    left:auto;
    right:10px;
}

JavaScript

$(document).ready(function () {
    var totalWidth = 0;

    $(".gallery_item").each(function () {
        totalWidth = totalWidth + $(this).outerWidth(true);
    });

    var maxScrollPosition = totalWidth - $(".gallery-wrap").outerWidth();
    function toGalleryItem($targetItem) {
        if ($targetItem.length) {

            var newPosition = $targetItem.position().left;

            if (newPosition <= maxScrollPosition) {

                $targetItem.addClass("active-item");

                $targetItem.siblings().removeClass("active-item");

                $(".gallery").animate({
                    left: -newPosition
                }, 600, 'swing');
            } else {

                $(".gallery").animate({
                    left: -maxScrollPosition
                }, 600, 'swing');
            };
        };
    };

    $(".gallery").width(totalWidth);

    $(".gallery_item:first").addClass("active-item");
    $(".gallery_controls-prev").click(function () {
        var $targetItem = $(".active-item").prev();
        toGalleryItem($targetItem);
    });
    
    $(".gallery_controls-next").click(function () {
        var $targetItem = $(".active-item").next();
        toGalleryItem($targetItem);
    });

});