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

              
                <!DOCTYPE html>
<html lang="en">
  <body>
<main>
    <div class="sky-slider">
      <ul class="sky-slider__img-container">
        <li class="active"><img src="https://images.unsplash.com/photo-1551336711-cf9a1763637c?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60" /></li>
        <li><img src="https://images.unsplash.com/photo-1551986782-74b48e9c3175?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60" /></li>
        <li><img src="https://images.unsplash.com/photo-1551415923-a2297c7fda79?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60" /></li>
        <li><img src="https://images.unsplash.com/photo-1551225404-5a0f49b60ad2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60" /></li>
        <li><img src="https://images.unsplash.com/photo-1551225249-cb5dd379b29b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60" /></li>
      </ul>

      <div class="sky-slider-controls">
        <ul>
          <li class="sky-slider__prev">
            <button>
               <svg class="chevron-right" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 306 306">
                    <polygon points="94.35,0 58.65,35.7 175.95,153 58.65,270.3 94.35,306 247.35,153 "/>
                </svg>
            </button>
          </li>
          
          <li class="sky-slider__next">
            <button>
              <svg class="chevron-right" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 306 306">
                  <polygon points="94.35,0 58.65,35.7 175.95,153 58.65,270.3 94.35,306 247.35,153 "/>
              </svg>
            </button>
          </li>
        </ul>
      </div>
  </div><!-- end of sky-slider-->
</main>

  </body>
</html>
              
            
!

CSS

              
                
//IRE Reset
html, body,
h1, h2, h3, h4, h5, h6,
a, p, span,
em, small, strong,
sub, sup,
mark, del, ins, strike,
abbr, dfn,
blockquote, q, cite,
code, pre,
ol, ul, li, dl, dt, dd,
div, section, article,
main, aside, nav,
header, hgroup, footer,
img, figure, figcaption,
address, time,
audio, video,
canvas, iframe,
details, summary,
fieldset, form, label, legend,
table, caption,
tbody, tfoot, thead,
tr, th, td {
    margin: 0;
    padding: 0;
    border: 0;
}

:root {
  font-size: 62.5%;
  body {
    // Body font size 16px
    font-size: 1.6rem;
    background: #58a5dd;
  }
}

main,.container{
  width: 120rem;
  margin: 0 auto;
}


/*Sky Slider Styles */
.sky-slider{
  width: 100%;
  position: relative;
  transition: 300ms ease-in-out;
  
  .sky-slider__img-container{
      list-style: none;
      display: block;
      
      
      li{
        display: none;
        
        &.active{
          display:block;
        }
        
        img{
          margin: 0 auto;
          display: block;
        }
        
      }
      
  }//end of sky-slider__img-container
  
  //Controls
  .sky-slider-controls{
    top: 50%;
    transform: translateY(-50%);
    position: absolute;
    width: 100%;
    min-height: 6rem;
    
    ul{
        display: block;
        position: relative;
        list-style: none;
      
      li{
        position: absolute;
      }
      .sky-slider__prev{
        left: -1px;
        background: rgba(255, 255, 255, 0.8);
        
        button{
          display: inline-block;
          border: none;
          background: none;
          cursor: pointer;
          background-size: 2.4rem 2.4rem;
          padding: 1rem;
          height: 6rem;
          width: 6rem;

          .chevron-right{
            height: 100%;
            fill: #999;
            transition: fill .3s ease-in;
            transform: rotateY(180deg); 
          }
          
          &:hover{
            .chevron-right{
              fill: #777;
              transition: fill .3s ease-in-out;
            }
          } //end of hover
          
        }//end of button
          
      }//end of sky-slider__prev
      
      .sky-slider__next{
        right: -1px;
        background: rgba(255, 255, 255, 0.8);
        
        button{
          display: inline-block;
          border: none;
          background: none;
          cursor: pointer;
          background-size: 2.4rem 2.4rem;
          padding: 1rem;
          height: 6rem;
          width: 6rem;

          .chevron-right{
            height: 100%;
            fill: #999;
            transition: fill .2s ease-in-out;
          }
          
          &:hover,
          &:focus{
            outline: none;
            
            .chevron-right{
              fill: #777;
              transition: fill .2s ease-in;
            }
          } //end of hover

        }//end of button
        
      }
    }
    
  }//end of sky-slider__controls
  
}//end of sky-slider

@media screen and (min-width:320px){
  main{
    width: 100%;
  }
  
  
 
}//end of min width 320

              
            
!

JS

              
                /*
image slider

Main Goal: Cycle Images

Features Added:
  - Next and Previous Arrow Navigation ✓
	- Cycle (Loop) Images ✓
  - Keyboard Control ✓
 
Features Needed:
  - Auto loop images
	- Randomize Images
	- Set Image Count Limits
*/

let skyslider = () => {
  
  /********************************
  Main Constant Variables
  ********************************/
  
  //variable finds main slider container
  const $skySlider = document.querySelector('.sky-slider');
  
  //variable finds all slider images
  const $skySliderSlides  = document.querySelector('.sky-slider__img-container li');

  //variable for Previous Button
  const $skySliderPrev  = document.querySelector('.sky-slider__prev');
  
  //variable for Next Button
  const $skySliderNext  = document.querySelector('.sky-slider__next');
  
  //auto loop
  const $autoLoop = true;
  const autoLoopTime = {
    time: 5000
  };
  

  
  //autoLoopTime = 4000;
  if( $autoLoop == true){
    window.setInterval(autoSlide, autoLoopTime.time); 
  }
  
  
  /********************************
  Previous Slide Functionality
  - Click to the Previous Slide
  ********************************/
  //creating method to move Previous
  const slideToPrevious = (e) => {
    
    //prevents default behavior of element 
    e.preventDefault();
    
    //Find the current slide
    let $currentSlide = document.querySelector('.sky-slider__img-container .active');
    
    // Find the previous slide
    let $previousSlide = $currentSlide.previousElementSibling;
    
    if($previousSlide !== null){
      $currentSlide.classList.remove('active');
      $previousSlide.classList.add('active'); 
    }
    
    //Determines if the active slide is the first
    // when clicking prev it finds the last slide
    if($currentSlide === document.querySelector(".sky-slider__img-container li.active:first-child")){
      let $lastSlide = document.querySelector(".sky-slider__img-container li:last-child");
      $currentSlide.classList.remove('active');
      $lastSlide.classList.add('active'); 
    }
    
  };//end of SlideToPrevious
  
  
  /********************************
  Next Slide Functionality
  - Click to the Next Slide
  ********************************/
  //creating method to move Next
  const slideToNext = (e) => {

    //prevents default behavior of element 
    e.preventDefault();
    
    //Find the current slide
    let $currentSlide = document.querySelector('.sky-slider__img-container .active');
    
    // Find the previous slide
    let $nextSlide = $currentSlide.nextElementSibling;
    
    if($nextSlide !== null){
      $currentSlide.classList.remove('active');
      $nextSlide.classList.add('active'); 
    }
    
    // Determines if the active slide is the last, 
    // when clicking prev it finds the first slide
    if($currentSlide === document.querySelector(".sky-slider__img-container li.active:last-child")){
      let $firstSlide = document.querySelector(".sky-slider__img-container li:first-child");
      $currentSlide.classList.remove('active');
      $firstSlide.classList.add('active'); 
    }
    
    
  };//end of SlideToNext
                
  
  /********************************
  Arrow Key Functionality
  ********************************/
  
  // Create eventListener for click on the left arrow
  $skySliderPrev.addEventListener('click', slideToPrevious, false);

  // Create eventListener for click on the right arrow
  $skySliderNext.addEventListener('click', slideToNext, false);
  
  // Create new custom event for sliding to the left
  const slideLeftEvent = new Event('slideLeft');

  // Create new custom event for sliding to the right
  const slideRightEvent = new Event('slideRight');

  // Create eventListener for pressing the left key
  $skySliderPrev.addEventListener('slideLeft', slideToPrevious, false);

  // Create eventListener for pressing the right key
  $skySliderNext.addEventListener('slideRight', slideToNext, false);

  // Listen to keydown event
  document.addEventListener('keydown', (e) => {
    e = e || window.event;

     if (e.keyCode === 37) {
      // If pressed key was left arrow
      $skySliderPrev.dispatchEvent(slideLeftEvent);
     } else if (e.keyCode === 39) {
      // If pressed key was right arrow
      $skySliderNext.dispatchEvent(slideRightEvent);
     }
    }, false);
  
  /********************************
  Loop Functionality
  ********************************/
  
  /*
    - determine how many images in loop
    - set a time interval  for how long to show each slide
    - 
    
  */
  
  
  /********************************
  Next Slide Functionality
  - Click to the Next Slide
  ********************************/
  
  
  //creating method to move Next
 
  function autoSlide(){
     //Find the current slide
    let $currentSlide = document.querySelector('.sky-slider__img-container .active');
    
    // Find the previous slide
    let $nextSlide = $currentSlide.nextElementSibling;
    
    if($nextSlide !== null){
      $currentSlide.classList.remove('active');
      $nextSlide.classList.add('active'); 
    }
    
    // Determines if the active slide is the last, 
    // when clicking prev it finds the first slide
    if($currentSlide === document.querySelector(".sky-slider__img-container li.active:last-child")){
      let $firstSlide = document.querySelector(".sky-slider__img-container li:first-child");
      $currentSlide.classList.remove('active');
      $firstSlide.classList.add('active'); 
    }
  };//end of autoSlide

  
  
                                                 
};//end of skySlider




document.addEventListener('DOMContentLoaded', function(){
  let skyslide = skyslider();
//autoLoopTime.time = 6000;
});
              
            
!
999px

Console