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 includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                <!-- hidden is a semantic attribute to hide elements -->
<!-- having a number input adds more security that the value will always be a number -->
<input id="js-imageSource-index" type="number" value="0" hidden/>
<!-- <button onclick="loopPoses()">Loop</button> -->
<!-- Adding js- is a great way to seprate js related ID's or classes  -->
<button id="js-slide-trigger">Loop</button>
<img id="js-slide" width="300" height="300" src="https://images.pexels.com/photos/69738/pexels-photo-69738.jpeg?auto=compress&cs=tinysrgb&dpr=2&w=500"/>

              
            
!

CSS

              
                
              
            
!

JS

              
                // don't use global variables that are mutable this will make 
// code harder to comprehensive i.e. the code can go in multiple 
// directions if the value can be changed by anyone
// var i = 0;          // Start Point
var imageElem = document.getElementById('js-slide')
var triggerElem = document.getElementById("js-slide-trigger")
var ImagesIndexElem = document.getElementById('js-imageSource-index')
var imageSources = [
  [
      'https://images.pexels.com/photos/684385/pexels-photo-684385.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=640',
      'https://images.pexels.com/photos/1040157/pexels-photo-1040157.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=650', 
      'https://images.pexels.com/photos/373076/pexels-photo-373076.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=640'
  ],
  [
    'https://images.pexels.com/photos/860538/pexels-photo-860538.jpeg?auto=compress&cs=tinysrgb&dpr=2&w=500',
    'https://images.pexels.com/photos/36029/aroni-arsa-children-little.jpg?auto=compress&cs=tinysrgb&dpr=2&w=500', 
    'https://images.pexels.com/photos/688675/pexels-photo-688675.jpeg?auto=compress&cs=tinysrgb&dpr=2&w=500'
  ]
];  

// This will tell javascript to wait
// don't worry about how it works if you aren't familiar with promises yet
// see: https://www.youtube.com/watch?v=2d7s3spWAzo for more on Promises
// P.S. I just copy pasted this from google.
const wait = (amount = 0) => new Promise(resolve => setTimeout(resolve, amount));


async function slideShow(){
//   1. If you read this value outside function this will can be changed in 
//      view but javascript variable will not be changed so it will get stale
//   2. Cast the value to Number  
  
  /* 1 */
  const topIndex = /* 2 */ Number(ImagesIndexElem.value)
//  This will only work if index is below images length 
  if (topIndex < imageSources.length) {
    const imagesOfThisIndex = imageSources[topIndex]
    
    for (var middleIndex = 0; middleIndex < imagesOfThisIndex.length; middleIndex++) {
//       wait (in milliseconds)
      await wait(1000)
      imageElem.src = imagesOfThisIndex[middleIndex]
    }
    
//     after slideshow is completed increase the topIndex
    ImagesIndexElem.value = topIndex + 1
  }
}

triggerElem.addEventListener('click', slideShow)
              
            
!
999px

Console