JSFiddle - React, Tailwind, and code Playground
HTML
<div id="container">
<img src="http://www.team-clanx.org/testing/jedi.jpg" class="scrollItem"/>
<img src="http://www.team-clanx.org/testing/jedi.jpg" class="scrollItem"/>
<img src="http://www.team-clanx.org/testing/jedi.jpg" class="scrollItem"/>
</div>
CSS
#container
{
width: 700px;
height: 48px;
border: #c0c0c0 solid 1px;
position: relative; /* Notice the relative positioning */
overflow: hidden;
}
.scrollItem
{
visibility: hidden;
position: absolute; /* Absolute makes it so we can position slides */
}
JavaScript
// Get a reference to our slides and the container
var items = $(".scrollItem");
var container = $("#container");
function scrollLeft() {
// For each slide calculate its new "left" after moving it over 1 pixel
items.each(function() {
var item = $(this);
var newLeft = item.position().left - 1;
item.css("left", newLeft);
// Check if the slide's right edge is off the "stage"
// If so, reset the slide to be just right of the container's right edge
var rightEdge = newLeft + item.outerWidth(true);
if (rightEdge <= 0) {
item.css("left", container.outerWidth() + 'px');
}
});
}
$(function() {
var leftEdgeStart = container.outerWidth();
// Set each slide to be in single file
$(".scrollItem").each(function() {
$(this).css("left", leftEdgeStart + 'px');
leftEdgeStart += $(this).outerWidth(true);
});
// Once all lined up, set them to be visible
items.css("visibility", "visible");
// Start our scrolling, every 35 milliseconds
setInterval(scrollLeft,35);
});