Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <h1>Parallaxe Multiply Layer</h1>
<div>
  <p>Use the Checkboxes to test Scroll or Mouse Parallax</p>
  <input type="checkbox" id="mm" checked value="mouse move">
  <label for ="mm">Parallax on Mouse move</label>
  <input type="checkbox" id="sm" checked value="scroll move">
  <label for ="sm">Parallax on Scroll</label>
</div>
<section class="container">
  
  <div class="element-wrapper">
    Rectangle
    <div class="image-layer" data-image-layer="tardis"></div>
    <svg width="100%" height="100%" class="parallaxe-layer">
      <rect x="25%" y="25%" width="50%" height="50%" fill="#55F545"/>
    </svg>
  </div>
  
  <div class="element-wrapper">
    Circle
    <div class="image-layer" data-image-layer="tardis"></div>
    <svg width="100%" height="100%" class="parallaxe-layer">
      <circle cx="50%" cy="50%" r="30%" fill="#55F545" />
    </svg>
  </div>
  
  <div class="element-wrapper">
    Path
    <div class="image-layer" data-image-layer="tardis"></div>
    <svg width="100%" height="100%" class="parallaxe-layer">
      <path d="M164.06,212.46C147.19,140.6,0,0,0,0H81.56s-26.78,90.38-15,109.27c13,20.77,82.92,6.74,97.5-12.14C177.32,80,164.06,0,164.06,0h93.75s-14.42,87,0,105.63c7.46,9.65,42.19,0,42.19,0V212.46l-53,68.6-83-.61-15,19.43-67.5-87.42,140.63-98.34L29.06,159V267.1s223.82,74,247.5,0c8-25-59.06-76.49-59.06-76.49S183,265.83,165.94,257.39C157.83,253.36,166.59,223.22,164.06,212.46Z" transform="translate(-3 -2)" fill="#55F545"/>
    </svg>
  </div>
  
  <div class="element-wrapper">
    Polygon
    <div class="image-layer" data-image-layer="tardis"></div>
    <svg width="100%" height="100%" class="parallaxe-layer">
      <polygon points="150,20 330,190 110,280" fill="#55F545" />
    </svg>
  </div>
  <div class="element-wrapper">
    Text
    <div class="image-layer" data-image-layer="tardis"></div>
    <svg width="100%" height="100%" class="parallaxe-layer">
      <text x="100" y="10" fill="#55F545" transform="rotate(30 20,40)" font-size="5.5em" font-weight="bold">JUST</text>
      <text x="40" y="100" fill="#55F545" transform="rotate(30 20,40)" font-size="5.5em" font-weight="bold">TEXT!</text>
    </svg>
  </div>
  
  <div class="element-wrapper">
    Rectangle with Offset + Blur filter
    <div class="image-layer" data-image-layer="tardis"></div>
    <svg width="100%" height="100%" class="parallaxe-layer">
      <filter id="f1" x="0" y="0" width="200%" height="200%">
        <feOffset result="offOut" in="SourceGraphic" dx="30" dy="30" />
        <feGaussianBlur result="blurOut" in="offOut" stdDeviation="5" />
        <feBlend in="SourceGraphic" in2="blurOut" mode="normal" />
      </filter>
      <rect x="25%" y="25%" width="50%" height="50%" fill="#55F545" stroke="red" stroke-width="6px" filter="url(#f1)" />
    </svg>
  </div>
</section>
<div class="spacer">for more scrolling</div>
              
            
!

CSS

              
                * { margin: 0; padding: 0; box-sizing: border-box; vertical-align: middle; }

html, body { height: 100%; }
body {
  text-align: center;
  padding: 1.5rem;
}

h1 {
  display: inline-block;
  font-weight: normal;
  border-bottom: thin solid black;
  margin: 1em;
}

.container {
  display: flex;
  min-height: 15em;
  flex-wrap: wrap;
  justify-content: center;
}

.element-wrapper {
  margin: 5em;
  position: relative;
  width: 20%;
  height: 20em;
  div {
    position: absolute;
  }
}

[data-image-layer] {
  position: relative;
  height: 100%;
  width: 100%;
  background-size: cover;
  background-position-x: center;
  background-blend-mode: multiply;
  transition: background-color .5s;
}

.parallaxe-layer {
  mix-blend-mode: multiply;
}  

[data-image-layer="tardis"] { background-image: url(http://thenerdstash.com/wp-content/uploads/2015/05/Tardis-HD-2.jpg); }


.spacer {min-height: 1000px;}

//IE Fallback
.no-background-blend-mode .parallaxe-layer {
  opacity: 0.6;
}
              
            
!

JS

              
                document.addEventListener("DOMContentLoaded", function(){
	initParallax();
  
  document.addEventListener('mousemove', mouseParallax);
  document.addEventListener('scroll', scrollParallax)
});

var cursorX = 0; var cursorY = 0;
var offsetX = 0; var offsetY = 0;
var depthXY = 0;
var scenes; var layers;   

// Initialize variables
function initParallax() {
  scenes = document.querySelectorAll('.element-wrapper');
  layers = document.querySelectorAll('svg');
}               

// Called on scroll
function scrollParallax(event) {
  if(document.getElementById('sm').checked) {
    sP(layers, 0.9);
  }
}

// Called on Mouse move
function mouseParallax(event) {
  if(document.getElementById('mm').checked) {
    mP(event);
  }
}

//Mouse move Parallax 
function mP() {
  cursorX = event.clientX;
  cursorY = event.clientY;
  for(i = 0; i<=layers.length; i++){
    depthXY = 0.3;
    offsetX = ((cursorX * depthXY) / 8);
    offsetY = ((cursorY * depthXY) / 8);
    layers[i].style.transform = 'translate3d('+offsetX+'px,'+offsetY+'px,0px)';
  }
}

//Scrolling Parallax
function sP($object, multiplier){
  multiplier = typeof multiplier !== 'undefined' ? multiplier : 0.5;
  multiplier = 1 - multiplier;
  var from_top = window.pageYOffset;
  var bg_css = '0' +(multiplier * from_top) + 'px';
  for (var index = 0 ; index < $object.length; index++) {
    $object[index].style.marginTop = bg_css;
  }
}; 

//IE Fallback
if(typeof window.getComputedStyle(document.body).backgroundBlendMode == 'undefined') {
  document.documentElement.className += " no-background-blend-mode";
}
              
            
!
999px

Console