cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

            
              <div class="slider"></div>

            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Racing+Sans+One|Roboto');

@function randomVal() {
  @return random(256) - 1;
}

@mixin randomRGBA() {
  background-color: rgba(randomVal(), randomVal(), randomVal(), .25);
}

body {
 // overflow: hidden;
  height: 100%;
}

.slide {
  display: flex;
  flex-wrap: nowrap;
  flex-direction: column;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  opacity: 0;
  z-index: 1;
  transition: opacity 1s;
 
  @media (min-width: 768px) {
    flex-direction: row;
    flex-wrap: wrap;
  }
  
  
  &.visible {
    opacity: 1;
    z-index: 2;
  }
}

$slides: 6;
@while $slides>=0 {
  .slide[data-slide="slide-#{$slides}"] {
    @include randomRGBA();
  }
  $slides: $slides - 1;
}

.slide-image {
  flex: 0 1 50%;

  img {
    width: 100%;
    height: 75vh;
    object-fit: cover;
  
    @media (min-width: 768px) {
      height: 100vh;
    }
  }
}

.slide-caption {
  flex: 0 1 50%;
  display: flex;
  background-color: inherit;
}

.slide-caption-content {
  margin: auto;
  width: 100%;
  font-family: 'Roboto', sans-serif;
  line-height: 1;
  font-size: calc(14px + (19 - 14) * (100vw - 426px) / (768 - 426));
  background-color: inherit;
  padding: 0 .5em;
  
  @media(min-width: 768px) {
    width: 90%;
    line-height: 1.5;
    font-size: 1.25rem;
  }
  
  p {
    padding: 0 1em;
  }
}

.title-bg {
  background-color: inherit;
  padding: 0 .75em;

  h1 {
    font-family: 'Racing Sans One', serif;
    font-size: calc(28px + (44 - 28) * (100vw - 426px) / (768 - 426));
    font-weight: 700;
    line-height: 1.2;
    padding: 5px 0;
    
    @media(max-width: 425px) {
      margin: 0;
    }
    
    @media(min-width: 768px) {
      font-size: 2.8125rem;
    }
    
  }
}
            
          
!
            
              const sliderData = [
  {
    img: "https://images-na.ssl-images-amazon.com/images/M/MV5BMTk2NTI1MTU4N15BMl5BanBnXkFtZTcwODg0OTY0Nw@@._V1_SY1000_CR0,0,675,1000_AL_.jpg",
    name: "The Avengers",
    desc: "Earth's mightiest heroes must come together and learn to fight as a team if they are to stop the mischievous Loki and his alien army from enslaving humanity."
  },
  {
    img: "https://images-na.ssl-images-amazon.com/images/M/MV5BMTczNTI2ODUwOF5BMl5BanBnXkFtZTcwMTU0NTIzMw@@._V1_SY1000_CR0,0,674,1000_AL_.jpg",
    name: "Iron Man",
    desc: "After being held captive in an Afghan cave, billionaire engineer Tony Stark creates a unique weaponized suit of armor to fight evil."
  },
  {
    img: "https://images-na.ssl-images-amazon.com/images/M/MV5BOGE4NzU1YTAtNzA3Mi00ZTA2LTg2YmYtMDJmMThiMjlkYjg2XkEyXkFqcGdeQXVyNTgzMDMzMTg@._V1_SY1000_CR0,0,674,1000_AL_.jpg",
    name: "Thor",
    desc: "The powerful but arrogant god Thor is cast out of Asgard to live amongst humans in Midgard (Earth), where he soon becomes one of their finest defenders."
  },
  {
    img: "https://images-na.ssl-images-amazon.com/images/M/MV5BMTAwMjU5OTgxNjZeQTJeQWpwZ15BbWU4MDUxNDYxODEx._V1_SY1000_CR0,0,674,1000_AL_.jpg",
    name: "Guardians of the Galaxy",
    desc: "A group of intergalactic criminals are forced to work together to stop a fanatical warrior from taking control of the universe."
  },
  {
    img: "https://images-na.ssl-images-amazon.com/images/M/MV5BNjgwNzAzNjk1Nl5BMl5BanBnXkFtZTgwMzQ2NjI1OTE@._V1_SY1000_CR0,0,674,1000_AL_.jpg",
    name: "Doctor Strange",
    desc: "While on a journey of physical and spiritual healing, a brilliant neurosurgeon is drawn into the world of the mystic arts."
  },
  {
    img: "https://images-na.ssl-images-amazon.com/images/M/MV5BMTYzOTc2NzU3N15BMl5BanBnXkFtZTcwNjY3MDE3NQ@@._V1_SY1000_CR0,0,640,1000_AL_.jpg",
    name: "Captain America",
    desc: 'Steve Rogers, a rejected military soldier transforms into Captain America after taking a dose of a "Super-Soldier serum". But being Captain America comes at a price as he attempts to take down a war monger and a terrorist organization'
  }
];

for (let i = 0; i < sliderData.length; i++) {
  const slider = document.querySelector(".slider");
  const {img, name, desc} = sliderData[i];
  const slideData = `
    <div class="slide ${i == 0 ? 'visible' : ''}" data-slide="slide-${i}">
      <div class="slide-image">
       <img src="${img}" />
      </div>
      <div class="slide-caption">
        <div class="slide-caption-content">
          <div class="title-bg">
            <h1>${name}</h1>
          </div>
          <p>${desc}</p>
        </div>
      </div>
    </div>
  `;
  slider.innerHTML += slideData;
}

const slides = document.querySelectorAll(".slide");
let currentSlide = 0;
const slideInterval = setInterval(() => {
  slides[currentSlide].classList.remove("visible");
  currentSlide = (currentSlide + 1) % slides.length;
  slides[currentSlide].classList.add("visible");
}, 5000);

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console