Nation Library - Slideshow example
Shows what is required to create a basic slideshow
by NationStudio
HTML
<script src="https://techdocs.wearenation.co.uk/nation/Utils.js"></script>
<script src="https://techdocs.wearenation.co.uk/nation/Animation.js"></script>
<script src="https://techdocs.wearenation.co.uk/nation/EventDispatcher.js"></script>
<script src="https://techdocs.wearenation.co.uk/nation/Slideshow.js"></script>
<div class="js-slideshow">
<div class="js-slide">
<!-- Optional caption. Note that it's expected for every slide to have a caption, if captions are enabled, even if the caption is blank -->
<div class="js-caption">Slide 1</div>
</div>
<div class="js-slide">
<div class="js-caption">Slide 2</div>
</div>
<div class="js-slide">
<div class="js-caption">Slide 3</div>
</div>
<div class="js-slide">
<div class="js-caption">Slide 4</div>
</div>
<!-- Optional navigation -->
<div class="navigation">
<button class="js-previous button">
Previous
</button>
<button class="js-next button">
Next
</button>
</div>
<!-- Optional Pips -->
<ul class="js-pips">
<li class="js-pip">1</li>
<li class="js-pip">2</li>
<li class="js-pip">3</li>
<li class="js-pip">4</li>
</ul>
<!-- Optional Captions -->
<div class="js-captions">
</div>
<!-- Optional Slide Count -->
<p class="slide-count">
<span class="js-current">1</span> /
<span class="js-total">1</span>
</p>
</div>
CSS
.js-slideshow {
position: relative;
width: 50%;
overflow: hidden;
}
.js-slide {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 200px;
background: #0D398B;
}
.js-slide:first-child {
position: relative;
}
.js-slide:nth-child(2n+1) {
background: #0C54D9;
}
/* Optional navigation */
.navigation {
position: absolute;
left: 10px;
bottom: 10px;
width: 33.33%;
}
.button {
width: 100%;
margin: 10px 0 0 0;
padding: 5px 0;
border: 2px solid #ccc;
background: #fff;
cursor: pointer;
line-height: 1.313em;
transition: background 0.3s linear;
box-sizing: border-box;
}
.button:hover {
background: #eee;
}
/* Optional Pips */
.js-pips {
position: absolute;
right: 0;
bottom: 0;
width: 33.33%;
list-style: none;
}
.js-pip {
display: inline-block;
width: 20%;
text-align: center;
color: #333;
border-radius: 50%;
background: #fff;
cursor: pointer;
}
.js-pip.active {
background: #7ff6d1;
}
/* Optional Captions */
.js-captions {
position: absolute;
top: 10px;
left: 10px;
margin: 0;
padding: 0;
width: 90%;
line-height: 1em;
font-weight: 700;
}
.js-caption {
position: absolute;
top: 0;
left: 0;
color: #fff;
font-family: sans-serif;
}
.slide-count {
position: absolute;
top: 10px;
right: 10px;
margin: 0;
padding: 0;
color: #fff;
font-family: sans-serif;
font-weight: 700;
}
JavaScript
// Element containing slides that have a class of either 'js-slide' or 'slide'
var element = document.documentElement.querySelector(".js-slideshow");
// Choice of 'slide' or 'fade' transition styles (defaults to fade)
var options = {
slide: true,
easing: "easeInOutQuad",
pips: true,
useCaptions: true
}
// Instantiate the slideshow with the above options
var slideshow = new NATION.Slideshow(element, options);