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="slide-input">
  <label>Number of Item Per Slider</label>
    <input type="text" id="txt-item-per-slide" value="1" onchange="updateItemPerSlide(this)" />
</div>
<div class="image-container">
  <div class="image-navigation nav-left-arrow" onclick="prevNavClick()"><</div>
  <div class="image-wrapper">
    <div class="image-slider">
      <div class="image-slider-item">
        <img src="https://farm6.staticflickr.com/5682/32485550974_a17009c6a1_b.jpg" /> 
      </div>
      <div class="image-slider-item">
        <img src="https://farm3.staticflickr.com/2813/13229959125_ca374e42ce_b.jpg" />
      </div>
      <div class="image-slider-item">
        <img src="https://farm5.staticflickr.com/4230/35641415276_ed8617f4c9_b.jpg" />
      </div>
      <div class="image-slider-item">
        <img src="https://farm3.staticflickr.com/2813/13229959125_ca374e42ce_b.jpg" />
      </div>
      <div class="image-slider-item">
        <img src="https://farm5.staticflickr.com/4230/35641415276_ed8617f4c9_b.jpg" />
      </div>
      <div class="image-slider-item">
        <img src="https://farm3.staticflickr.com/2813/13229959125_ca374e42ce_b.jpg" />
      </div>
      <div class="image-slider-item">
        <img src="https://farm5.staticflickr.com/4230/35641415276_ed8617f4c9_b.jpg" />
      </div>
    </div>
  </div>
  <div class="image-navigation nav-right-arrow" onclick="nextNavClick()">></div>
</div>


              
            
!

CSS

              
                .slide-input{
 display: flex;
 justify-content:center;
  margin-bottom: 20px;
}
.slide-input label{
  padding: 1rem;
}
.slide-input input{
 text-align:center;
  border-radius: 5px;
}

.image-container{
  display: flex;
  flex-flow: row nowrap;
  align-item: stretch;
}

.image-navigation{
  font-weight: 600;
  font-size: 5rem;
  flex: 1 1 5%;
  display: flex;
  align-items: center;
  cursor: pointer;
}
.nav-right-arrow{
  justify-content: flex-start;
}
.nav-left-arrow{
    justify-content: flex-end;
  visibility: hidden;
}
.image-wrapper{
  flex: 1 1 90%;
  overflow: hidden;
}
.image-slider{
  transition:transform 1s ease-in-out;
  white-space: nowrap;
  margin: 0;
  padding: 0;
}
.image-slider-item{
  display: inline-block;
  background-size: cover;
  background-position: 50% 50%;
}
.image-slider-item img{
  width: 100%;
  height: 100%;
}


.container{
  display: flex;
  flex-flow: row nowrap;
  align-items: stretch;
}
.navigation{
  flex: 1 1 5%;
  display: flex;
  align-items: center;
  cursor: pointer;
}
.left-arrow{
  justify-content: flex-end
}
.right-arrow{
  justify-content: flex-start
}
.wrapper {
  flex: 1 1 90%;
  overflow: hidden;
}
.slider{
  transition: transform 1s ease-in-out;
  list-style-type: none;
  white-space: nowrap;
  margin: 0;
  padding:0;
}
.slider-item{
  display: inline-block;
  width: 100%;
  height: 250px;
  background-size: cover;
  background-position: 50% 50%;
}

@keyframes slide {
  100% {
        transform:translate3d(180deg);
    }
}
              
            
!

JS

              
                const getElement = (selector) => {
    return document.querySelector(selector);
}
const getElements = (selector) => {
  return document.querySelectorAll(selector);
}

let imagePosition = 0;
const sliderItems = document.querySelectorAll(".image-slider-item");
const totalImageItems = document.querySelectorAll(".image-slider-item").length;
const imageSliderWrapper = document.querySelector('.image-wrapper');
const imageWrapperWidth = imageSliderWrapper.offsetWidth;
const imageWrapperHeight = imageSliderWrapper.offsetHeight;
const firstElement = sliderItems[0];
const lastElement = sliderItems[sliderItems.length - 1];
const itemWidth = firstElement.offsetWidth;
let itemPerSlide = document.getElementById('txt-item-per-slide').value >> 0;
document.styleSheets[0].insertRule('.image-slider-item { width: '+ 100/itemPerSlide +'%; }', 0);
const setImageSliderTransform = () => {
  const slider = document.querySelector('.image-slider');
  const itemWidth = sliderItems[0].offsetWidth;
  slider.style["transform"] = 'translate3d(' + (-imagePosition * itemWidth - imagePosition*3) + 'px,0,0)';
}
function updateItemPerSlide(element) {
  imagePosition = 0;
  itemPerSlide = element.value >> 0;
  document.styleSheets[0].removeRule('.image-slider-item { width: '+ 100/itemPerSlide +'%; }', 0);
  document.styleSheets[0].insertRule('.image-slider-item { width: '+ 100/itemPerSlide +'%; }', 0);
}
function prevNavClick()  {
  const firstElementLeft = firstElement.getBoundingClientRect().left;
  const lastElementRight = lastElement.getBoundingClientRect().right;
  imagePosition = Math.max(imagePosition - 1, 0);
  if(imagePosition === 0){
   document.getElementsByClassName("nav-left-arrow")[0].style['visibility'] = 'hidden';
  }
  if(imagePosition + itemPerSlide < totalImageItems){
    document.getElementsByClassName("nav-right-arrow")[0].style['visibility'] = 'visible';
  }
  setImageSliderTransform();
}

function nextNavClick() {
  const firstElementLeft = firstElement.getBoundingClientRect().left;
  const lastElementRight = lastElement.getBoundingClientRect().right;
  imagePosition = Math.min(imagePosition + 1, totalImageItems - 1);
  if(imagePosition > 0){
   document.getElementsByClassName("nav-left-arrow")[0].style['visibility'] = 'visible';
  }
  if(imagePosition + itemPerSlide === totalImageItems){
   document.getElementsByClassName("nav-right-arrow")[0].style['visibility'] = 'hidden';
  }
  setImageSliderTransform();
}

window.onload = function(){
  if(sliderItems.length <= itemPerSlide){
      document.getElementsByClassName("nav-right-arrow")[0].style['visibility'] = 'hidden'; 
  }
}
/*
let position = 0;
const slider = getElement(".slider");
const sliderWrapper = getElement(".wrapper");
const totalItems = getElements(".slider-item").length

const setTransform = () => {
    slider.style["transform"] = 'translate3d(' + (-position * slider.offsetWidth - position*3) + 'px,0,0)';
}

function prevClick()  {
  position = Math.max( position - 1, 0);
  setTransform()
}

function nextClick() {
  position = Math.min( position + 1, totalItems - 1);
  setTransform();
}
window.addEventListener('resize', setTransform);
*/
              
            
!
999px

Console