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

              
                <p class="hover">select mode + hover = ?</p>
<div class="wrapper">
  <svg viewBox="0 0 180 100">
    <filter id='noise' x='0%' y='0%' width='100%' height='100%'>
        <feTurbulence type="fractalNoise" baseFrequency="0" result="noise" numOctaves="3" seed="10"/>
      <feDisplacementMap in="SourceGraphic" in2="noise" scale="10" xChannelSelector="R" yChannelSelector="R"></feDisplacementMap>  
  </filter>    
  </svg>
  <div class="split">
    <div class="list-outer">
      <ul id="imageList">
        <li class="bold">image blend</li>
        <li class="active" data-mode="normal">normal</li> 
        <li data-mode="multiply">multiply</li>
        <li data-mode="screen">screen</li>
        <li data-mode="overlay">overlay</li>
        <li data-mode="darken">darken</li>
        <li data-mode="lighten">lighten</li>
        <li data-mode="color-dodge">color-dodge</li>
        <li data-mode="color-burn">color-burn</li>
        <li data-mode="difference">difference</li>
        <li data-mode="exclusion">exclusion</li>
        <li data-mode="hue">hue</li>
        <li data-mode="saturation">saturation</li>
        <li data-mode="color">color</li>
        <li data-mode="luminosity">luminosity</li>
      </ul>
      <ul id="overlayList">
        <li class="bold">overlay blend</li>
        <li data-mode="normal">normal</li> 
        <li class="active" data-mode="multiply">multiply</li>
        <li data-mode="screen">screen</li>
        <li data-mode="overlay">overlay</li>
        <li data-mode="darken">darken</li>
        <li data-mode="lighten">lighten</li>
        <li data-mode="color-dodge">color-dodge</li>
        <li data-mode="color-burn">color-burn</li>
        <li data-mode="difference">difference</li>
        <li data-mode="exclusion">exclusion</li>
        <li data-mode="hue">hue</li>
        <li data-mode="saturation">saturation</li>
        <li data-mode="color">color</li>
        <li data-mode="luminosity">luminosity</li>
      </ul>
    </div>
    <div id="container">
      <div id="inner">
        <div id="mask" class="turb-mask"></div>
        <img id="image" src="https://source.unsplash.com/Pzv28NRtgko/400x450/">
      </div>
    </div>
  </div>
</div>
	

              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

html {
  font-size: 17px;
}

body {
	padding: 0;
  margin: 0;
	font-family: sans-serif;
	font-size: 1rem;
}

.list-outer {
  display: flex;
  justify-content: space-between;
  padding: 2rem;
  
  > ul:first-child {
    margin-right: 5rem;
  }
  
  @media screen and (max-width: 50rem) {
    padding-top: 4rem;
  }
}

ul {
  list-style: none;
  line-height: 1.5;
  padding: 0;
  margin: 0;
  
  li {
    cursor: pointer;
    font-size: 0.8em;
  }
}

.active {
  font-weight: bold;
}

.bold {
  font-weight: bold;
  letter-spacing: 0.05em;
  margin-bottom: 0.05em;
  font-size: 1rem;
}

svg {
	height: 0;
	width: 0;
	visibility: hidden;
}

.hover {
  position: fixed;
  top: 1rem;
  right: 1rem;
  margin: 0;
  font-weight: bold;
  font-style: italic;
  letter-spacing: 0.05em;
}

.wrapper {
	max-width: 1600px;
  min-height: 100vh;
  margin-left: auto;
  margin-right: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.split {
  width: 100%;
  display: flex;
  justify-content: space-around;
  align-items: center;
  flex-direction: column;
  
  @media screen and (min-width: 50rem) {
    flex-direction: row;
  }
}

#container {
  perspective: 1.5rem;
}

#inner {
  position: relative;
  overflow: hidden;
  box-shadow: 2px 2px 50px rgba(0, 0, 0, 0.4);
  transition: transform 0.5s;
  display: flex;
  
  img {
    mix-blend-mode: normal;
    max-width: 100%;
    height: auto;
  }
}

.turb-mask {
  position: absolute;
  width: 110%;
  height: 110%;
  left: -5%;
  top: -5%;
  opacity: 0.5;
  pointer-events: none;
  background-color: rgba(255, 0, 0, 0.65);
  background-image: url(https://source.unsplash.com/Pzv28NRtgko/400x450/);
  background-size: cover;
  background-position: center;
  background-blend-mode: multiply;
  z-index: 0;
  -webkit-filter: url(#noise);
	filter: url(#noise);
}
              
            
!

JS

              
                const container = document.getElementById('container'),
      mask = document.getElementById('mask'),
	    turbVal = { val: 0.0 },
      octavesVal = { val: 0 },
	    turb = document.querySelector('#noise feTurbulence'),
      
      turbTl = gsap.timeline({ 
        paused: true, 
        repeat: -1,
        yoyo: true,
        onUpdate: function(){
          turb.setAttribute('baseFrequency', turbVal.val);
          // turb.setAttribute('numOctaves', octavesVal.val);
        }}),

      maskTl = gsap.timeline({ paused: true });

turbTl.to(turbVal, 12, { ease: Sine.easeInOut, val: 0.03 });

maskTl.to(mask, 0.5, { ease: Sine.ease, opacity: 0.9 })

container.addEventListener('mouseenter', e => {
  turbTl.restart();
  maskTl.restart();
});

container.addEventListener('mouseleave', e => {
  turbTl.delay(0.5).reverse(1);
  maskTl.reverse(1);
});

const imageListItem = document.querySelectorAll('#imageList li'),
      overlayListItem = document.querySelectorAll('#overlayList li'),
      image = document.getElementById('image');

for (const item of imageListItem) {
  item.addEventListener('click', function(e) {
    imageListItem.forEach(node => {
      node.classList.remove('active');
    });
    e.currentTarget.classList.add('active');
    image.style.mixBlendMode = this.getAttribute('data-mode');
  })
}

for (const item of overlayListItem) {
  item.addEventListener('click', function(e) {
    overlayListItem.forEach(node => {
      node.classList.remove('active');
    });
    e.currentTarget.classList.add('active');
    mask.style.backgroundBlendMode = this.getAttribute('data-mode');
  })
}

// Handle perspective, from: https://css-tricks.com/animate-a-container-on-mouse-over-using-perspective-and-transform/

(function() {
  // Init
  var container = document.getElementById("container"),
      inner = document.getElementById("inner");

  // Mouse
  var mouse = {
    _x: 0,
    _y: 0,
    x: 0,
    y: 0,
    updatePosition: function(event) {
      var e = event || window.event;
      this.x = e.clientX - this._x;
      this.y = (e.clientY - this._y) * -1;
    },
    setOrigin: function(e) {
      this._x = e.offsetLeft + Math.floor(e.offsetWidth / 2);
      this._y = e.offsetTop + Math.floor(e.offsetHeight / 2);
    },
    show: function() {
      return "(" + this.x + ", " + this.y + ")";
    }
  };

  mouse.setOrigin(container);
  
  var counter = 0;
  var updateRate = 10;
  var isTimeToUpdate = function() {
    return counter++ % updateRate === 0;
  };

  var onMouseEnterHandler = function(event) {
    update(event);
  };

  var onMouseLeaveHandler = function() {
    inner.style = "";
  };

  var onMouseMoveHandler = function(event) {
    if (isTimeToUpdate()) {
      update(event);
    }
  };

  var update = function(event) {
    mouse.updatePosition(event);
    updateTransformStyle(
      (mouse.y / inner.offsetHeight / 2).toFixed(2),
      (mouse.x / inner.offsetWidth / 2).toFixed(2)
    );
  };

  var updateTransformStyle = function(x, y) {
    var style = "rotateX(" + x + "deg) rotateY(" + y + "deg)";
    inner.style.transform = style;
    inner.style.webkitTransform = style;
    inner.style.mozTransform = style;
    inner.style.msTransform = style;
    inner.style.oTransform = style;
  };

  container.onmouseenter = onMouseEnterHandler;
  container.onmouseleave = onMouseLeaveHandler;
  container.onmousemove = onMouseMoveHandler;
})();




// Another idea for later
// function onMouseMove(e) { 
//    var rect = this.getBoundingClientRect()
    
//     // Find its child
//    var follower = this.querySelector('#mask')
    
//    TweenMax.to(follower, 0.3, {
//      x: e.offsetX,
//      y: e.offsetY,
//      ease:Power4.easeOut
//    })
// }

// function init() {
//   // Listen for mouse movement when over either one of the parents
//   container.addEventListener('mousemove', onMouseMove)
// };

// document.addEventListener("DOMContentLoaded", function(event) {
//   // wait until window, stylesheets, images, links, and other media assets are loaded
//   window.onload = function() {         
//     // Center the pivot point of the follower
//     TweenMax.set('#mask', {
//       xPercent: -50,
//       yPercent: -50
//     })

//     // All ready, start!
//     init();
//   };
// });
              
            
!
999px

Console