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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <!DOCTYPE html>
<html lang="en">

<head>

  <style>
    .banner {
      visibility: hidden;
    }
  </style>

  <title>300x250</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

  <link href="https://fonts.googleapis.com/css?family=Roboto:500,700&display=swap" rel="stylesheet">
  <link rel="stylesheet" type="text/css" href="css/style.css">

  <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.1.2/TweenMax.min.js"></script>
  <script type="text/javascript">var clickTag = "http://www.yourfallbackurl.com"; </script>
</head>

<body>
  <a href="javascript:window.open( window.clickTag )">

    <div class="banner">

      <div class="slider">

        <div id="img1" class="slider__img slider__img--3"></div>
        <div id="img2" class="slider__img slider__img--2"></div>
        <div id="img3" class="slider__img  slider__img--1"></div>

        <div class="slider__gradient"></div>

        <div class="slider__header"><span class="slider__hword--500" id="hword1">BARCELONA,</span><span class="slider__hword--500" id="hword2">&nbsp;BE</span>
          <span class="slider__hword--700" id="hword3">&nbsp;PART OF IT.</span></div>

        <div id="left-nav" class="slider__left-nav"></div>
        <div id="right-nav" class="slider__right-nav"></div>

        <div class="slider__opaq-band"></div>

        <div id="hname1" class="slider__hname">
          <p>MESSAGE NO ONE</p>
        </div>

        <div id="hname2" class="slider__hname">
          <p>MESSAGE NO 2</p>
        </div>

        <div id="hname3" class="slider__hname slider__hname--tight ">
          <p>MESSAGE NO 3</p>
        </div>

        <div class="slider__para"></div>

      </div>

      <div class="bottom-bar">

        <div class="bottom-bar__logo"></div>
        <div class="bottom-bar__cta">CLICKME</div>

      </div>

    </div>

    <script src="js/animation.js"></script>
  </a>
</body>

</html>
              
            
!

CSS

              
                /* ROUGH DEMO*/

body,
body * {
  font-family: "Roboto", sans-serif;
  vertical-align: baseline;
  border: 0 none;
  outline: 0;
  padding: 0;
  margin: 0;
  color: hsl(0, 0%, 100%);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.banner {
  background: hsl(0, 0%, 0%);
  overflow: hidden;
  position: absolute;
  width: 300px;
  height: 250px;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  border: 1px solid hsl(0, 0%, 20%);
}

.bottom-bar {
  position: absolute;
  width: 300px;
  height: 54px;
  bottom: 0px;
}

.bottom-bar__logo {
  position: absolute;
  width: 111px;
  height: 28px;
  bottom: 12px;
  left: 12px;
  background-image: url("https://demo.thomasthorstensson.co.uk/codepens/ad_mpu_javascript_slider/img/logo%402x.png");
  background-repeat: none;
  background-size: 111px 28px;
}

.bottom-bar__cta {
  position: absolute;
  display: inline-block;
  letter-spacing: 2.34px;
  font-weight: 500;
  text-align: center;
  color: white;
  background-color: hsl(4, 90%, 58%);
  padding: 8px 15px;
  text-align: center;
  text-decoration: none;
  font-size: 11px;
  bottom: 12px;
  right: 12px;
}

/* ==========================================================================
   SLIDER AND PARTS
   ========================================================================== */

.slider__gradient {
  position: absolute;
  width: 300px;
  height: 83px;
  left: 0px;
  top: 0px;
  background-image: url("https://demo.thomasthorstensson.co.uk/codepens/ad_mpu_javascript_slider/img/overlay.png");
  background-repeat: none;
  background-size: 300px 83px;
}

.slider {
  position: absolute;
  top: 0px;
  left: 0px;
  width: 300px;
  height: 198px;
}

.slider__left-nav,
.slider__right-nav {
  z-index: 99;
  position: absolute;
  width: 43px;
  height: 43px;
  bottom: 65px;
}

.slider__left-nav {
  left: -3px;
  background-image: url("https://demo.thomasthorstensson.co.uk/codepens/ad_mpu_javascript_slider/img/arrow_left%402x.png");
  background-repeat: none;
  background-size: 43px 43px;
}

.slider__right-nav {
  right: -3px;
  background-image: url("https://demo.thomasthorstensson.co.uk/codepens/ad_mpu_javascript_slider/img/arrow_right%402x.png");
  background-repeat: none;
  background-size: contain;
}

.slider__opaq-band {
  position: absolute;
  width: 300px;
  height: 20px;
  bottom: 4px;
  left: 0;
  background-image: url("https://demo.thomasthorstensson.co.uk/codepens/ad_mpu_javascript_slider/img/transp_band.png");
  background-repeat: none;
  background-size: contain;
}

.slider__hname {
  position: absolute;
  left: 20px;
  bottom: 6px;
  font-size: 12px;
  letter-spacing: 0.5px;
  font-weight: 400;
}

.slider__hname--tight {
  letter-spacing: 0px;
}

/* Slider hearder */

.slider__header {
  width: auto;
  position: absolute;
  left: 20px;
  top: 25px;
}

.slider__hword--500,
.slider__hword--700 {
  font-size: 14px;
  letter-spacing: 3px;
  display: inline-block;
  margin-top: 1.5px;
  color: white;
}

.slider__hword--500 {
  font-weight: 500;
}

.slider__hword--700 {
  font-weight: 700;
}

/* Slider images */

.slider__img {
  width: 300px;
  height: auto;
}

.slider__img--1 {
  position: absolute;
  width: 300px;
  height: 196px;
  bottom: 4px;
  left: 0;
  background-image: url("https://demo.thomasthorstensson.co.uk/codepens/ad_mpu_javascript_slider/img/image1%402x.jpg");
  background-repeat: none;
  background-size: contain;
}

.slider__img--2 {
  position: absolute;
  width: 300px;
  height: 196px;
  bottom: 4px;
  left: 0;
  background-image: url("https://demo.thomasthorstensson.co.uk/codepens/ad_mpu_javascript_slider/img/image2%402x.jpg");
  background-repeat: none;
  background-size: contain;
}

.slider__img--3 {
  position: absolute;
  width: 300px;
  height: 196px;
  bottom: 4px;
  left: 0;
  background-image: url("https:///demo.thomasthorstensson.co.uk/codepens/ad_mpu_javascript_slider/img/image3%402x.jpg");
  background-repeat: none;
  background-size: contain;
}

#hname2,
#hname3 {
  opacity: 0;
}

:focus {
  outline: none;
}

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

              
            
!

JS

              
                function Ad() {

    //Slider properties
    this.slideIndex = 0;
    this.prevIndex = 0;
    this.tmr = '';
    this.tmrInterval = 5000;

    //Dom properties
    this.el = {};
    this.el.body = document.body;
    this.el.leftNav = document.querySelector('#left-nav');
    this.el.rightNav = document.querySelector('#right-nav');

    this.imgArray = ["#img3", "#img2", "#img1"];
    this.hNameArray = ["#hname1", "#hname2", "#hname3"];

    //Timeline properties
    this.anime = new TimelineMax({ repeat: 0 });
    this.animeUI = new TimelineMax();
    this.setDefault();
    this.showBanner();

    //Auto
    this.startTimer();
    this.hidden = '';

    //Visibility change for inactive tab
    var visibilityChange;
    if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support 
        this.hidden = "hidden";
        visibilityChange = "visibilitychange";
    } else if (typeof document.msHidden !== "undefined") {
        this.hidden = "msHidden";
        visibilityChange = "msvisibilitychange";
    } else if (typeof document.webkitHidden !== "undefined") {
        this.hidden = "webkitHidden";
        visibilityChange = "webkitvisibilitychange";
    }

    document.addEventListener(visibilityChange, this.handleVisibilityChange.bind(this), false);

}

Ad.prototype.handleVisibilityChange = function () {
    if (document[this.hidden]) {
        this.clearTimer();
    } else {
        this.clearTimer();
        this.startTimer();
    }
};

Ad.prototype.showBanner = function () {
    this.bindEvents();
    this.anime.from(".banner", 0.2, { autoAlpha: 0 }, "0");
};

// and possibly also replay
Ad.prototype.bindEvents = function () {
    this.el.leftNav.addEventListener('click', this, false);
    this.el.rightNav.addEventListener('click', this, false);
};

Ad.prototype.startTimer = function () {
    this.tmr = setInterval(this.simulRightClick.bind(this), 4000);
};

Ad.prototype.clearTimer = function () {
    clearInterval(this.tmr);
};

Ad.prototype.simulRightClick = function () {
    this.el.rightNav.click();
};

Ad.prototype.clickLeftHandler = function (e) {
    this.animeUI.to(this.el.leftNav, .2, { x: -5, yoyo: true, repeat: 1 });
    (this.slideIndex > 0) ? this.slideIndex -= 1 : this.slideIndex = 2; 
    this.showImage();
};

Ad.prototype.clickRightHandler = function (e) {
    this.animeUI.to(this.el.rightNav, .2, { x: +5, yoyo: true, repeat: 1 });
    (this.slideIndex < 2) ? this.slideIndex += 1 : this.slideIndex = 0; 
    this.showImage();
};

Ad.prototype.setDefault = function () {
    this.anime.set("#img2", { autoAlpha: 0 });
    this.anime.set("#img1", { autoAlpha: 0 });
    this.anime.to("#img3", 0.1, { autoAlpha: 1 });
};

Ad.prototype.isNot = function (value) {
    console.log("isnot " + value)
    return value !== this.imgArray[this.slideIndex];
};

Ad.prototype.isNotName = function (value) {
    return value !== this.hNameArray[this.slideIndex];
};

Ad.prototype.showImage = function () {
    // for images
    var toShow = this.imgArray[this.slideIndex];
    var toHideArr = this.imgArray.filter(this.isNot.bind(this)); 
 
    this.anime.to(toHideArr, 1, { autoAlpha: 0 });
    this.anime.to(toShow, 2, { autoAlpha: 1 },"-=1"); 

    // for texts
    var toShowText = this.hNameArray[this.slideIndex];
    this.anime.to(this.hNameArray, .5, { autoAlpha: 0 }, "-=2"); 
    this.anime.to(toShowText, .5, { autoAlpha: 1 }, "-=1.2");
};

Ad.prototype.handleEvent = function (e) {
    e.preventDefault();
    switch (e.type) {
        case 'click':
            this.clearTimer();
            this.startTimer(); 
            if (e.target.id == "left-nav") { this.clickLeftHandler(); }
            if (e.target.id == "right-nav") { this.clickRightHandler(); }
            break;
        case 'webkitTransitionEnd':
            //this.transitionEndHandler(e);
            break;
        default:

            break;
    }
};

window.onload = function (e) {
    window.ad = new Ad();
};
              
            
!
999px

Console