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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                

<html lang="en">
<head>
  <meta data-template-name="Template_H5T_inpage-300x250-image">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta name="ad.size" content="width=300,height=250">
    <script type="text/javascript">var clickTag = "http://www.example.com"</script>
  <link rel="stylesheet" type="text/css" href="style.css">
  <link href='https://fonts.googleapis.com/css?family=Roboto:300,500,700' rel="stylesheet">
  <script type="text/javascript" src="https://s0.2mdn.net/ads/studio/Enabler.js"></script>
  <script type="text/javascript" src="https://s0.2mdn.net/ads/studio/cached_libs/tweenmax_1.19.0_643d6911392a3398cb1607993edabfa7_min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" type="text/javascript"></script>
    <style>
    /*#main-container {
        visibility: hidden;
    }*/
    </style>
</head>
<body>
    <div id="main-container">
      <div id="exit"></div>

      <div class="feature" id="feature">
        <div id="main-img-0"></div>
        <div id="logo"></div>
        <div id="greyTop"></div>
        <div id="blueTop"></div>
        <div id="bottomGrey"></div>
        <div id="redtrack"></div>
        <div id="crossing"></div>
        <div id="blueDot"></div>
        <div id="yellowSign"></div>
        <div id="bubble"></div>
        <div id="line1">Unlock the roadblock.</div>
        <div id="line2">Get real-time<br/>traffic updates.</div>
        <div id="line3">Find the fastest route.</div>
        <div id="cta">Check on Google Maps</div>
        <div id="line4">#LookBeforeYouLeave</div>
    
        <div id="truck"></div>
      </div>
    </div>

  <script src="logic.js"></script>
</body>
</html>
              
            
!

CSS

              
                
body, body * {
  vertical-align: baseline;
  border: 0 none;
  outline: 0;
  padding: 0;
  margin: 0;
  font-family: Arial, sans-serif;
  font-size: 9pt;
  color: #333;
}


#main-container {
  position: absolute;
  width: 300px;
  height: 250px;
  border: 1px solid black;
  box-sizing: border-box;
  background: #EEE;
}

#exit {
  position: absolute;
  top: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
  z-index: 50;
  opacity: 0;
}

.feature {
  top: 0;
  left:0;
  width: 298px;
  height: 248px;
  position: absolute;
  display: none;
  overflow: hidden;
}
#main-img-0 {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url(https://res.cloudinary.com/dxt70fisd/image/upload/v1479984335/plain-map-600x500_onz6i7.jpg);
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center center;
  display: block;
}

:focus {
  outline:none;
}
::-moz-focus-inner {
  border:0;
}

#logo {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url(https://res.cloudinary.com/dxt70fisd/image/upload/v1479984334/logo-600x500_wwdped.png);
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center center;
  display: block;
}

#greyTop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url(https://services.google.com/fh/files/emails/greytrack-600x500.png);
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center center;
  display: block;
}
#blueTop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url(https://res.cloudinary.com/dxt70fisd/image/upload/v1479984335/topbluetrack-600x500_jcpmef.png);
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center center;
  display: block;
}

#bottomGrey {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url(https://services.google.com/fh/files/emails/bottomgreytrack-600x500.png);
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center center;
  display: block;
  z-index: 5;
}

#redtrack {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url(https://res.cloudinary.com/dxt70fisd/image/upload/v1479984335/redtrack-600x500_yspo1l.png);
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center center;
  display: block;
  z-index: 4;
}

#crossing {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url(https://services.google.com/fh/files/emails/crossing1-600x500.png);
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center center;
  display: block;
}

#blueDot {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url(https://services.google.com/fh/files/emails/bluedot.png);
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center center;
  display: block;
  z-index: 6;
}

#yellowSign {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url(https://res.cloudinary.com/dxt70fisd/image/upload/v1479984335/yellowsign-600x500_rdi3v5.png);
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center center;
  display: block;
  z-index: 6;
}

#bubble {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url(https://res.cloudinary.com/dxt70fisd/image/upload/v1479984334/bubble-600x500_jhvqoc.png);
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center center;
  display: block;
}

#truck {
    position: absolute;
    top: 0;
    height: 0;
    display: block;
    z-index: 10;
}

.truck{
  position: absolute;
  width: 33px;
  top: 0;
  height: 0;
  display: block;

}

#line1, #line2 {
  padding-top: 200px;
  position: absolute;  
  width: 300px;
  text-align: center;
  visibility: hidden;
}

#line3 {
  width: 300px;
  text-align: center;
  padding-top: 100px;
}

#cta {
  font-family: 'Roboto', sans-serif;
  text-align: center;
  color: #ffffff;
  background: #4b87ea;
  border-radius: 2px;
  font-weight: 100;
  padding: 9px 10px;
  width: 180px;
  margin: auto;
  letter-spacing: 0.5px;
  margin-top: 10px;
}

#line4 {
  width: 300px;
  text-align: center;
  padding-top: 60px;
}


              
            
!

JS

              
                
// Reference to the creative's various properties and elements.
var creative = {};
var loop = 0;
var tl = new TimelineMax();

/**
 * Called on the window load event.
 */
function preInit() {
  setupDom();

  if (Enabler.isInitialized()) {
    init();
  } else {
    Enabler.addEventListener(studio.events.StudioEvent.INIT, init);
  }
}

/**
 * Set up references to DOM elements.
 */
function setupDom() {
  creative.dom = {};
  creative.dom.mainContainer = document.getElementById('main-container');
  creative.dom.exit = document.getElementById('exit');
  creative.dom.image0 = document.getElementById('main-img-0');
  creative.dom.lastframe = document.getElementById('lastframe');
}

/**
 * The Enabler is now initialized and any extra modules have been loaded.
 */
function init() {

  creative.dom.logo = document.getElementById('logo');
  creative.dom.greyTop = document.getElementById('greyTop');
  creative.dom.blueTop = document.getElementById('blueTop');
  creative.dom.bottomGrey = document.getElementById('bottomGrey');
  creative.dom.redtrack = document.getElementById('redtrack');
  creative.dom.crossing = document.getElementById('crossing');
  creative.dom.blueDot = document.getElementById('blueDot');
  creative.dom.yellowSign = document.getElementById('yellowSign');
  creative.dom.bubble = document.getElementById('bubble');
  creative.dom.line1 = document.getElementById('line1');
  creative.dom.line2 = document.getElementById('line2');
  creative.dom.cta = document.getElementById('cta');
  creative.dom.truck = document.getElementById('truck');

console.log("addListeners")
  addListeners();
  // Wait for the page to load (also known as polite loading).
  if (Enabler.isVisible()) {
    showAd();
  }
  else {
    Enabler.addEventListener(studio.events.StudioEvent.VISIBLE, showAd);
  }
}

/**
 * Add appropriate listeners after the creative's DOM has been set up.
 */
function addListeners() {
  console.log("listening");
  creative.dom.exit.addEventListener('click', exitClickHandler);
}


/**
 *  Shows the ad.
 */

/**
 * Da fix.
 */
function showAd() {
    loadedImages = [];
    preloadImage(document.getElementById('truck'), 'truck', 'https://res.cloudinary.com/dxt70fisd/image/upload/v1479984335/truck-loop_yqvdvk.gif');
}

function preloadImage(parent, childClass, source) {
    loader = new Image();
    loader.src = source + '?v=' + new Date().getTime();

    loader.onload = function(event) {
        var img = event.target;
        img.classList.add(childClass);
        imageCounter(parent, img);
    };
}

function imageCounter(parent, img) {

    var temp = {
        parent: parent,
        child: img
    };

    loadedImages.push(temp);

    if (loadedImages.length === 1) {
        for (var i = 0; i < loadedImages.length; i++) {
            // console.log('endpoint:', loadedImages[i]);
            loadedImages[i].parent.appendChild(loadedImages[i].child);
        }

        // Double density amend
        var elements = document.getElementsByClassName('truck');
        var requiredElement = elements[0];
        requiredElement.style.width = '33px';
        requiredElement.style.height = 'auto';

        creative.dom.exit.style.display = "block";
        creative.dom.image0.style.visibility  = 'visible';

        document.getElementsByClassName('feature')[0].style.display = 'block';

        initAnim();

    }
}
// ---------------------------------------------------------------------------------
// End fix.
// -


// ---------------------------------------------------------------------------------
// MAIN
// ---------------------------------------------------------------------------------

function exitClickHandler(e) {
  console.log('exit');
  Enabler.exit('BackgroundExit');
  tl.seek(tl.duration(), true);
  tl.pause();
}

function initAnim() {

  console.log("INIT ANIM");

  // if (loop < 2) {
  //   tl.pause(0, true);
  // }

  // tl.play();

  tl.set(truck, {rotation: 51, x: 118, y: 83})
    .from(crossing, 0.5, {autoAlpha: 0})
    .from(truck, 2, {x:-150, y:250})
    .from(greyTop, 0.5, {autoAlpha: 0})
    .from([bubble, line1], 1.5, {autoAlpha:0}, "-=0.5")
    .from(blueTop, 0.5, {autoAlpha: 0})
    .from(redtrack, 0.5, {autoAlpha: 0})
    .from(bottomGrey, 0.5, {autoAlpha: 0})
    .to(line1, 0.5, {autoAlpha:0})
    .from(yellowSign, 0.5, {autoAlpha: 0})
    .from(line2, 2.15, {autoAlpha:0})
    .to(line2, 0.85, {autoAlpha:0},"leave")
    .to(truck, 0.75, {autoAlpha: 0},"leave")
    .to([bubble, yellowSign,bottomGrey, redtrack, yellowSign, crossing, blueTop, greyTop, blueDot], 0.5, {autoAlpha: 0})
    .from([line3, line4, cta], 4, {autoAlpha:0, ease:Power4.easeOut})

  tl.call(loopCheck, ["param1"], this)
  
}

function loopCheck() {
  if (loop >= 2) {
    console.log("END");
    tl.pause();
    tl.invalidate();
  } else {

    initAnim();
  }
  loop++;
}



/**
 *  Main onload handler
 */
window.addEventListener('load', preInit);
              
            
!
999px

Console