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 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

              
                <div class="wrapper">
  <div class="ad">
    <div class="layer light"></div>
    <div class="layer light light-2"></div>
    <div class="layer layer-1"></div>
    <div class="layer layer-2"></div>
    <div class="layer layer-3"></div>
  </div>
</div>

<div class="description">
  <p>I guess parallax is back. This is my take on the Apple TV effect, which I'll be walking through during my upcoming presentation at <a href="http://www.dotcss.io/" target="_blank">dotCSS</a>. I've seen a few others around, but I wanted to nail the lighting effect. Make sure your browser supports <code>mix-blend-mode</code>.</p>
  <p class="me">From your pal <a href="https://twitter.com/attasi" target="_blank">@attasi</a></p>
</div>
              
            
!

CSS

              
                $tvItemWidth: 840px;
$tvItemHeight: 500px;

html,
body {
  min-height: 100%;
}

body {
  font-family: Helvetica, sans-serif;
  font-size: 18px;
  line-height: 1.5;
  color: #999;
  background: linear-gradient(160deg, #333, #222) #242424;
}

a {
  color: #56b2ff;
  text-decoration: none;
}

.wrapper {
  position: relative;
  height: 800px;
  -webkit-perspective: 800;
}

.layer {
  position: absolute;
  will-change: transform;
}

.ad {
  position: absolute;
  left: 50%;
  top: 50%;
  width: $tvItemWidth;
  height: $tvItemHeight;
  margin-left: -$tvItemWidth / 2;
  margin-top: -$tvItemHeight / 2;
  background: black;
  overflow: hidden;
  border-radius: 3px;
  -webkit-transform-style: preserve-3d;
  will-change: transform;
  box-shadow: 0 60px 100px rgba(0, 0, 0, 0.5);
}

.layer-1,
.layer-2,
.layer-3 {
  top: 50%;
  left: 50%;
  margin-left: -630px;
  margin-top: -375px;
  width: 1260px;
  height: 750px;
  transform: scale(.7);
}

.light {
  top: 50%;
  left: 50%;
  margin-left: -$tvItemWidth;
  margin-top: -$tvItemHeight * 1.6;
  width: $tvItemWidth * 2;
  height: $tvItemHeight * 2;
  background: radial-gradient(ellipse closest-side at center, #6C6C6C, black);
  mix-blend-mode: color-dodge;
  opacity: .6;
  z-index: 3;
}

.light-2 {
  z-index: 4;
  background: radial-gradient(ellipse closest-side at center, white, black);
  mix-blend-mode: screen;
  opacity: .3;
}

.layer-1 {
  background-image: url(http://demos.attasi.com/apple-tv/images/breaking-bad-layer-1.jpg);
}

.layer-2 {
  background-image: url(http://demos.attasi.com/apple-tv/images/breaking-bad-layer-2.png);
}

.layer-3 {
  background-image: url(http://demos.attasi.com/apple-tv/images/breaking-bad-layer-3.png);
}

.description {
  padding: 100px;
  background: black;
  
  p {
    max-width: $tvItemWidth;
    margin: 1em auto;
  }
  
  code {
    font-family: Monaco, monospace;
    color: #ccc;
  }
}

.me {
  font-size: 14px;
}
              
            
!

JS

              
                var $body = $('body');
var WIDTH = $body.width();
var HEIGHT = $body.height();
var $ad = $('.ad');
var $light = $ad.find('.light');
var $layer1 = $ad.find('.layer-1');
var $layer2 = $ad.find('.layer-2');
var $layer3 = $ad.find('.layer-3');

function moveAd(e) {
  var xPer = e.clientX / WIDTH;
  var yPer = e.clientY / HEIGHT;

  var rotateX = 5 - (yPer * 10);
  var rotateY = -5 + (xPer * 10);

  $ad.css({
    transform: 'rotateX(' + rotateX + 'deg) rotateY(' + rotateY + 'deg) '
  });

  var translateX = -5 + (xPer * 10);
  var translateY = -5 + (yPer * 10);

  $layer2.css({
    transform: 'scale(.7) translateX(' + translateX + 'px) translateY(' + translateY + 'px)'
  });

  $layer3.css({
    transform: 'scale(.7) translateX(' + (translateX * 2) + 'px) translateY(' + (translateY * 2) + 'px)'
  });

  var lightX = 800 - (xPer * 1600);
  var lightY = 300 - (yPer * 600);

  $light.css({
    transform: 'translateX(' + lightX + 'px) translateY(' + lightY + 'px)'
  });
}

$body.on('mousemove', moveAd);
              
            
!
999px

Console