JSFiddle - React, Tailwind, and code Playground
HTML
<div id="container">
<img src="http://www.team-clanx.org/testing/Desert.png" class="scrollItem"/>
<img src="http://www.team-clanx.org/testing/Lighthouse.png" class="scrollItem"/>
<img src="http://www.team-clanx.org/testing/Penguins.png" class="scrollItem"/>
</div>
CSS
#container
{
width: 698px;
height: 218px;
border: #c0c0c0 solid 1px;
position: relative;
overflow: hidden;
}
.scrollItem
{
visibility: hidden;
position: absolute;
}
JavaScript
// Get references to our slides and the container
var items = $(".scrollItem");
var container = $("#container");
function slideLeft() {
// For each slide, we are going to calculate the left
// Then trigger an animation which will move it left
items.each(function() {
var item = $(this);
var newLeft = item.position().left - container.outerWidth();
item.animate({"left" : newLeft}, 400, function() {
// At the end of this animation, check if it is off the "stage"
// If so, set it up to be to the right of our container
var rightEdge = newLeft + item.outerWidth(true);
if (rightEdge <= 0) {
item.css("left", container.outerWidth() + 'px');
}
});
});
}
$(function() {
var leftEdgeStart = 0;
// Set up our slides to be in single file starting at pixel 0 of our relative container.
$(".scrollItem").each(function() {
$(this).css("left", leftEdgeStart + 'px');
leftEdgeStart += $(this).outerWidth(true);
});
// Now set them all to be visible
items.css("visibility", "visible");
// Start our slide every 3 seconds
setInterval(slideLeft,3000);
});