How to make styled native slideshow ads
A slideshow ad combines multiple videos, images, or a combination of both that viewers can scroll through. It's often used to showcase several products at once, or to list a product's features. You can use native templates to create slideshow ad items that are tailored to your needs.
If you'd rather have all the necessary code (HTML, JavaScript and CSS) in the template, you should make your slideshow ad using a custom native ad template instead. For more information on the differences between custom native ads and styled native ads, read About native ad templates.
You will learn:
- How to create a template for a styled slideshow ad. You can customize the sample code to fit your needs.
- How to create a styled slideshow ad item once you have a styled slideshow template.
How to create a styled slideshow ad template
This template will require the user to provide the URLs to where the image creatives are hosted as well as the destination URLs for each image when creating the slideshow ad item.
- Click Templates in the left navigation menu. The Templates section will appear.
- Click Native Ad Templates. The Native Ad Templates subsection will appear.
- Click Add Native Ad Template. The New Native Template window will appear.
- Click Styled. The New Native Ad Template page will appear.
- Name the template then add the variables as needed. In our sample code, we used three Image URL variables and three URL (Raw) variables. We called the image URL variables ImageURL, ImageURL2, and ImageURL3, and the URL variables DestinationURL, DestinationURL2, and DestinationURL3.
- Enter the code in the HTML Template (Styled) field, then click Save Changes.
Here's the code we used in our example:
<div class="slideshow-container">
<div class="slides-container">
<div class="slide">
<div class="slide-label">
Advertisement 1
</div>
<a href="[TRACKING_LINK][%DestinationURL%]" target="_blank">
<img src="[%ImageURL%]">
</a>
</div>
<div class="slide">
<div class="slide-label">
Advertisement 2
</div>
<a href="[TRACKING_LINK][%DestinationURL2%]" target="_blank">
<img src="[%ImageURL2%]">
</a>
</div>
<div class="slide">
<div class="slide-label">
Advertisement 3
</div>
<a href="[TRACKING_LINK][%DestinationURL3%]" target="_blank">
<img src="[%ImageURL3%]">
</a>
</div>
<a class="prev">
<
</a>
<a class="next">
>
</a>
<div class="slideshow-close-button-container">
<span class="slideshow-close-button">×</span>
</div>
</div>
<div class="dot-container">
<div class="dot"></div>
<div class="dot"></div>
<div class="dot"></div>
</div>
</div>
You can now use this template to create a styled slideshow ad item.
How to create a styled slideshow ad item
- Go to the section of the relevant zone (Your AdButler > Publishers > Your Publisher > Your Zone) or campaign (Your AdButler > Advertisers > Your Advertiser > Your Campaign).
- Click Add Ad Item in the Ad Items table. The Add Ad Item window will appear.
- Click Native (Styled). The New Ad Item page will appear.
- Select your slideshow styled native ad template in the Template dropdown menu.
- Fill in the rest of the fields as needed, including the image URLs and destination URLs.
- Click Save Ad Item.
At this point, you have finished setting up the ad item on the AdButler interface. You must now add the JavaScript and style element needed to display this ad properly directly to your website. Here's the sample code that we used in our example. You must replace the zone tags and zone class in the code with your own zone tags and zone class.
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.slideshow-container {
max-width: 1000px;
position: relative;
margin: auto;
}
.slide-label {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
.slide {
display: none;
animation-name: fade;
animation-duration: 1.5s;
}
@keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
.slide:first-of-type {
display: block;
}
.slide img {
width: 100%;
}
.dot-container {
width: fit-content;
margin: 1rem auto;
}
.dot {
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.dot:first-of-type {
background-color: #717171;
}
.prev, .next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
margin-top: -22px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
.prev:hover, .next:hover {
background-color: rgba(0,0,0,0.8);
}
.slideshow-close-button-container {
position: absolute;
top: 15px;
right: 15px;
cursor: pointer;
}
.slideshow-close-button {
width: 26px;
text-align: center;
display: inline-block;
color: #ffffff;
font-size: 22px;
background: #000000;
border-radius: 26px;
user-select: none;
}
</style>
</head>
<body>
<!-- To Edit 1: Replace Zone Tags below here with your own --><script type="text/javascript">if (!window.AdButler){(function(){var s = document.createElement("script"); s.async = true; s.type = "text/javascript"; s.src = 'https://servedbyadbutler.com/app.js'; var n = document.getElementsByTagName("script")[0]; n.parentNode.insertBefore(s, n);}());}</script>
<div class="plc104325"></div>
<script type="text/javascript">
var AdButler = AdButler || {}; AdButler.ads = AdButler.ads || [];
var abkw = window.abkw || '';
var plc104325 = window.plc104325 || 0;
(function(){
var divs = document.querySelectorAll(".plc104325:not([id])");
var div = divs[divs.length-1];
div.id = "placement_104325_"+plc104325;
AdButler.ads.push({handler: function(opt){ AdButler.register(######, ######, [0,0], 'placement_104325_'+opt.place, opt); }, opt: { place: plc104325++, keywords: abkw, domain: 'servedbyadbutler.com', click: 'CLICK_MACRO_PLACEHOLDER' }});
})();</script>
<!-- Replace Zone Tags above here with your own -->
<script>
var slides, dots;
var currentSlideIndex = 0;
function showSlide(slideIndex) {
var prevSlideIndex = currentSlideIndex;
currentSlideIndex = slideIndex;
if (currentSlideIndex > slides.length - 1) {
currentSlideIndex = 0
}
if (currentSlideIndex < 0) {
currentSlideIndex = slides.length - 1;
}
slides[prevSlideIndex].style.display = "none";
dots[prevSlideIndex].style.backgroundColor = "#bbb";
slides[currentSlideIndex].style.display = "block";
dots[currentSlideIndex].style.backgroundColor = "#717171";
}
AdButler.ads.push(function () {
// To Edit 2: Update this class with your zone's class
var zoneClass = 'plc104325';
var wrapper = document.querySelector('.' + zoneClass);
wrapper.addEventListener(AdButler.EVENTS.LOAD, function (e) {
slides = document.querySelectorAll('.' + zoneClass + ' .slide');
dots = document.querySelectorAll('.' + zoneClass + ' .dot');
<!-- Below code makes the close button functional -->
var closeButton = document.querySelector('.' + zoneClass + ' .slideshow-close-button');
closeButton.addEventListener('click', function () {
document.querySelector('.' + zoneClass + ' .slideshow-container').style.display = 'none';
});
<!-- Below code makes the prev button functional -->
var prevButton = document.querySelector('.' + zoneClass + ' .prev');
prevButton.addEventListener('click', function () {
showSlide(currentSlideIndex - 1);
});
<!-- Below code makes the next button functional -->
var nextButton = document.querySelector('.' + zoneClass + ' .next');
nextButton.addEventListener('click', function () {
showSlide(currentSlideIndex + 1);
});
<!-- Below code allows clicking on the dots below the slideshow to go to a specific slide -->
// if you cannot use ES6, use the below code
for (var i = 0; i < dots.length; i++) {
dots[i].addEventListener('click', (function(j) {
return function() { showSlide(j); };
})(i));
}
// if you can use ES6, uncomment the below code and remove the above code block
// for (let i = 0; i < dots.length; i++) {
// dots[i].addEventListener('click', () => showSlide(i));
// }
});
});
</script>
</body>
</html>