How to make styled native expanding ads (two creatives)
Expanding ads are ads that increase in size to reveal the whole image or another image when the viewer clicks or hovers their mouse cursor over the ad. You can use native templates to create expanding 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 expanding 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.
If you want to make an expanding ad that has only one creative, read How to make expanding ads (one creative).
You will learn:
- How to create a template for a styled expanding ad (two creatives). You can customize the sample code to fit your needs.
- How to create a styled expanding ad (two creatives) ad item once you have a styled expanding ad (two creatives) template.
How to create a styled expanding ad (two creatives) template
This template will require the user to provide the URLs to where the image creatives are hosted when creating the expanding 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 two image URL variables for the images that will be in the ad. In our sample code, we called these variables ImageURL and ImageURL2.
- Enter the code in the HTML Template (Styled) field, then click Save Changes.
Here's the code we used in our example:
<div class="expand-container">
<div class="image-container image-container-1" >
<a target="_blank" href="[TRACKING_LINK]">
<img src="[%ImageURL%]">
</a>
</div>
<div class="image-container image-container-2">
<a target="_blank" href="[TRACKING_LINK]">
<img src="[%ImageURL2%]">
</a>
</div>
<div class="expand-close-button-container">
<span class="expand-close-button">×</span>
</div>
</div>
You can now use this template to create a styled expanding ad (two creatives) ad item.
How to create a styled expanding ad (two creatives) 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 expanding ad (two creatives) styled native ad template in the Template dropdown menu.
- Fill in the rest of the fields as needed, including the image URLs. If you entered a destination URL, you can test it by clicking Open Destination URL to the right of the field.
- 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>
.expand-container {
position: relative;
width: 950px;
height: 250px;
margin: 0 auto;
}
.image-container {
position: absolute;
top: 0;
left: 0;
transition: all 1s ease;
}
.image-container-1 a img {
height: 250px;
width: 950px;
}
.image-container-2 {
opacity: 0;
clip: rect(0, 950px, 250px, 0);
}
.image-container-2 a img {
height: 700px;
width: 950px;
}
.expand-close-button-container {
position: absolute;
top: 5px;
right: 5px;
cursor: pointer;
}
.expand-close-button {
width: 21px;
text-align: center;
display: inline-block;
color: #ffffff;
font-size: 18px;
background: #000000;
border-radius: 21px;
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="plc104333"></div>
<script type="text/javascript">
var AdButler = AdButler || {}; AdButler.ads = AdButler.ads || [];
var abkw = window.abkw || '';
var plc104333 = window.plc104333 || 0;
(function(){
var divs = document.querySelectorAll(".plc104333:not([id])");
var div = divs[divs.length-1];
div.id = "placement_104333_"+plc104333;
AdButler.ads.push({handler: function(opt){ AdButler.register(######, ######, [0,0], 'placement_104333_'+opt.place, opt); }, opt: { place: plc104333++, keywords: abkw, domain: 'servedbyadbutler.com', click: 'CLICK_MACRO_PLACEHOLDER' }});
})();</script>
<!-- Replace Zone Tags above here with your own -->
<script>
AdButler.ads.push(function () {
// To Edit 2: Update this class with your zone's class
var zoneClass = 'plc104333';
var wrapper = document.querySelector('.' + zoneClass);
wrapper.addEventListener(AdButler.EVENTS.LOAD, function (e) {
<!-- Below code makes the close button functional -->
var closeButton = document.querySelector('.' + zoneClass + ' .expand-close-button');
closeButton.addEventListener('click', function () {
document.querySelector('.' + zoneClass + ' .expand-container').style.display = 'none';
});
<!-- Below code makes the image expand/shrink when moused over -->
var expandContainer = document.querySelector('.' + zoneClass + ' .expand-container');
expandContainer.addEventListener('mouseover', function () {
document.querySelector('.' + zoneClass + ' .image-container-1').style.opacity = '0';
document.querySelector('.' + zoneClass + ' .image-container-2').style.clip = 'rect(0, 950px, 700px, 0)';
document.querySelector('.' + zoneClass + ' .image-container-2').style.opacity = '1';
});
expandContainer.addEventListener('mouseout', function () {
document.querySelector('.' + zoneClass + ' .image-container-1').style.opacity = '1';
document.querySelector('.' + zoneClass + ' .image-container-2').style.clip = 'rect(0, 950px, 250px, 0)';
document.querySelector('.' + zoneClass + ' .image-container-2').style.opacity = '0';
});
});
});
</script>
</body>
</html>