Nation Library - TiledSlideshow example

Shows how to create a slideshow that shows multiple slides at once.

by NationStudio

HTML

<script src="https://techdocs.wearenation.co.uk/nation/Utils.js"></script>
<script src="https://techdocs.wearenation.co.uk/nation/EventDispatcher.js"></script>
<script src="https://techdocs.wearenation.co.uk/nation/Animation.js"></script>
<script src="https://techdocs.wearenation.co.uk/nation/TiledSlideshow.js"></script>
<div class="js-tiled-slideshow">
  <div class="js-slides">
    <div class="js-slide">1</div>
    <div class="js-slide">2</div>
    <div class="js-slide">3</div>
    <div class="js-slide">4</div>
    <div class="js-slide">5</div>
    <div class="js-slide">6</div>
    <div class="js-slide">7</div>
    <div class="js-slide">8</div>
  </div>
  <button class="js-previous button">Previous slides</button>
  <button class="js-next button">Next slides</button>
</div>

CSS

/* Main container */
.js-tiled-slideshow {
  position: relative;
  width: 100%;
  max-width: 800px;
  overflow: hidden;
}

/* Slides container that will be positioned via the left attribute */
.js-slides {
  position: relative;
  font-size: 0px;
}

.js-slides:after {
  content: "";
  display: block;
  clear: both;
}

/* Slide styles */
.js-slide {
  float: left;
  width: 25%;
  height: 90px;
  padding-top: 60px;
  font-size: 16px;
  text-align: center;
  color: #7FF6D1;
  background: #0D398B;
}
.js-slide:nth-child(2n+1) {
  background: #0C54D9;
}

/* Navigation */
.button {
  position: absolute;
  top: 0;
  width: 5%;
  min-width: 100px;
  height: 100%;
  padding: 0;
  border: 0;
  color: #fff;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.2);
  transition: background 0.3s linear;
}
.button:hover {
  background: rgba(0, 0, 0, 0.7);
}

.js-previous {
  left: 0;
}
.js-next {
  right: 0;
}

JavaScript

// Element containing .js-slides and multiple .js-slide elements
var element = document.documentElement.querySelector(".js-tiled-slideshow");

// Just changing the easing on the animation between slides
var options = {
  easing: "easeInOutQuad"
};

// Create the slideshow
var slideshow = new NATION.TiledSlideshow(element, options);