Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
<div class="slideshow-container">
  <div class="image-container js-image-container">
    <img src="https://www.burkemuseum.org/sites/default/files/images/biology/herpetology/washington/northern-red-legged-frog1-1100x555.jpg" alt="">
    <img src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse1.mm.bing.net%2Fth%3Fid%3DOIP.nvq6PGh9_36OZfMLRf1gHwAAAA%26pid%3DApi&f=1" alt="">
    <img src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse3.mm.bing.net%2Fth%3Fid%3DOIP.ZMC1MgIlSLQPvjG16WMMXwHaHa%26pid%3DApi&f=1" alt="">
    <img src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse1.mm.bing.net%2Fth%3Fid%3DOIP.eUb1ehQq06wBn7evbMv2WgAAAA%26pid%3DApi&f=1" alt="">
  </div>
</div>

              
            
!

CSS

              
                
.slideshow-container {
  max-width: 100%;
  height: 300px;
  overflow: hidden;
  white-space: nowrap;
}

.image-container {
  width: auto;
  height: 300px;
  white-space: nowrap;
  font-size: 0;
  display: inline-block;
  overflow: hidden;

  img {
    display: inline;
    height: 300px;
  }
  &.is-animated {
    backface-visibility: hidden;
    perspective: 1000;
    animation: scroll-animation 12s linear infinite forwards;
  }
}

@keyframes scroll-animation {
  0% {
    transform: translate3d(0, 0, 0);
  }
  100% {
    transform: translate3d(var(--base-image-group-width), 0, 0);
  }
}

              
            
!

JS

              
                const container = document.querySelector('.js-image-container');
const parent = container.parentNode;
const images = container.querySelectorAll('img');

const insertImage = (container, images, index) => {
  const imageToInsert = images.item(index % images.length);
  const newDomEl = imageToInsert.cloneNode();
  container.appendChild(newDomEl);
};
const parentWidth = parent.clientWidth;

let containerWidth = container.clientWidth;
// max of 100 images to prevent some stupid infinite loop
let i;
let appendedImage = false;
for (i = 0; i < 100; i++) {
  // stop when we filled at least 100% of parent
  console.log(containerWidth, parentWidth);
  if (containerWidth > parentWidth) {
    break;
  }
  // insert image
  appendedImage = true;
  insertImage(container, images, i);
  containerWidth = container.clientWidth;
}

// Width of images at the time that whole parent was filled
const baseImageGroupWidth = container.clientWidth; 

// now duplicate images as to maintain illusion of infinity
const baseImages = container.querySelectorAll('img');
for (let j = 0; j < baseImages.length; j++) {
  insertImage(container, images, i + j);
}

let resetTargetWidth = baseImageGroupWidth;
if (appendedImage) {
  resetTargetWidth -= images.item(0).clientWidth; 
}
container.style.setProperty('--base-image-group-width', `-${resetTargetWidth}px`);
container.classList.add('is-animated');
              
            
!
999px

Console