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

              
                .hero
  .hero__inner  
    div.hero__image(data-x="0.05" data-y="0.05" data-scale="1.05")
      img(src="https://assets.codepen.io/450456/layer-sky.jpg")
    div.hero__image.hero__image--sun(data-x="0.065" data-y="0.065" data-scale="1.1")
      img(src="https://assets.codepen.io/450456/layer-sunNoSparkle.png")
    div.hero__image.hero__image--sparkle(data-x="0.065" data-y="0.065" data-scale="1.1")
      img(src="https://assets.codepen.io/450456/layer-sunSparkle.png")
    div.hero__image( data-x="0.09" data-y="0.09" data-scale="1.15")
      img(src="https://assets.codepen.io/450456/layer-smallField.png")
    div.hero__image(data-x="0.13" data-y="0.13" data-scale="1.15")
      img(src="https://assets.codepen.io/450456/layer-bigField.png")
    div.hero__image.hero__image--leaf7(data-x="0.17" data-y="0.17" data-scale="1.19")
      img(src="https://assets.codepen.io/450456/layer-leaf7Trans.png")
    div.hero__image.hero__image--leaf6(data-x="0.22" data-y="0.22" data-scale="1.2")
      img(src="https://assets.codepen.io/450456/layer-leaf6Trans.png")
    div.hero__image(data-x="0.25" data-y="0.25" data-scale="1.2")
      img(src="https://assets.codepen.io/450456/layer-leaf5.png")
    div.hero__image.hero__image--leaf4(data-x="0.28" data-y="0.28" data-scale="1.22")
      img(src="https://assets.codepen.io/450456/layer-leaf4Trans.png")
    div.hero__image(data-x="0.3" data-y="0.3" data-scale="1.25")
      img(src="https://assets.codepen.io/450456/layer-leaf3.png")
    div.hero__image.hero__image--leaf2(data-x="0.2" data-y="0.2" data-scale="1.18")
      img(src="https://assets.codepen.io/450456/layer-leaf2Trans.png")
    div.hero__image.hero__image--leaf1(data-x="0.28" data-y="0.28" data-scale="1.25")
      img(src="https://assets.codepen.io/450456/layer-leaf1Trans.png")
              
            
!

CSS

              
                html {
  background: #0c0f16;
}

.hero {
  width: 100%;
  position: relative;
  
  &::after {
    content: "";
    position: absolute;
    z-index: 2;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100px;
    background: linear-gradient(to bottom, transparent, #0c0f16);
  }
  
  &__inner {
    position: relative;
    overflow: hidden;
    padding-top: 62.51%;
    background: green;
    
    &::before {
      content: "";
      position: absolute;
      z-index: 2;
      top: 0;
      left: 0;
      bottom: 0;
      right: 0;
      background: #0c0f16;
      animation: intro 1s forwards;
    }
  }
  
  &__image {
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    // transition: all 100ms;
    
    img {
      width: 100%;
      position: relative;
    }
    
    &--sun {
      animation: sunrise 1.5s forwards;
      // animation-delay: 1s;
    }
    
    &--sparkle {
      animation: sparkle 6s infinite;
    }
    
    &--leaf1 {
      &::before {
        content: "";
        position: absolute;
        top: 13.9%;
        left: 2.5%;
        width: 18%;
        height: 13.5%;
        transform: rotate(135deg);
        background: linear-gradient(to left, #00ed8a 0%, #00ed8a 60%, white 80%, #00ed8a 100%);
        background-size: 200% 200%;
        animation: pulse 4s infinite;
      }
    }
    
    &--leaf2 {
      &::before {
        content: "";
        position: absolute;
        top: 45.5%;
        left: 6.5%;
        width: 18%;
        height: 13.5%;
        transform: rotate(46deg);
        background: linear-gradient(to left, #00ed8a 0%, #00ed8a 60%, white 80%, #00ed8a 100%);
        background-size: 200% 200%;
        animation: pulse 4s infinite;
        animation-delay: 2s;
        clip-path: polygon(11% 45%, 21% 14%, 28% 0, 100% 0, 100% 100%, 30% 100%, 21% 85%, 18% 73%);
      }
    }
    
    &--leaf4 {
      &::before {
        content: "";
        position: absolute;
        top: 85.9%;
        left: 20.5%;
        width: 22%;
        height: 13.5%;
        transform: rotate(125deg);
        background: linear-gradient(to left, #00ed8a 0%, #00ed8a 60%, white 80%, #00ed8a 100%);
        background-size: 200% 200%;
        animation: pulse 4s infinite;
        animation-delay: 1s;
      }
    }
    
    &--leaf6 {
      &::before {
        content: "";
        position: absolute;
        top: 26.5%;
        left: 71.5%;
        width: 18%;
        height: 13.5%;
        transform: rotate(27deg);
        background: linear-gradient(to left, #00ed8a 0%, #00ed8a 60%, white 80%, #00ed8a 100%);
        background-size: 200% 200%;
        animation: pulse 4s infinite;
      }
    }
    
    &--leaf7 {
      &::before {
        content: "";
        position: absolute;
        top: 62%;
        left: 78.8%;
        width: 17%;
        height: 13.5%;
        transform: rotate(125deg);
        clip-path: ellipse(50% 50% at 50% 50%);
        background: linear-gradient(to left, #00ed8a 0%, #00ed8a 60%, white 80%, #00ed8a 100%);
        background-size: 200% 200%;
        animation: pulse 4s infinite;
        animation-delay: 1s;
      }
    }
  }
}

@keyframes pulse {
  0%{background-position:0% 0%}
  50%{background-position:280% 280%}
  100%{background-position:0% 0%}
}

@keyframes sparkle {
  0%,
  30%,
  90%,
  100% {
    opacity: 0;
    clip-path: polygon(54.2% 42%, 54.2% 42%, 54.2% 42%, 54.2% 42%);
  }
  40%,
  80% {
    opacity: 0.9;
    clip-path: polygon(50% 35%, 60% 35%, 60% 50%, 50% 50%);
  }
  50% {
    opacity: 1;
    clip-path: polygon(50% 35%, 60% 35%, 60% 50%, 50% 50%);
  }
}

@keyframes intro {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@keyframes sunrise {
  0% {
    transform: translateY(100%) scale(1.1);
  }
  80% {
    transform: translateY(-1%) scale(1.1);
  }
  100% {
    transform: translateY(0) scale(1.1);
  }
}
              
            
!

JS

              
                const layers = document.querySelectorAll('.hero__image');

document.querySelector('.hero').addEventListener('mousemove',parallaxHero);
document.querySelector('.hero').addEventListener('touchmove',parallaxHero);

// apply initial scales
layers.forEach(function(layer, index){
  const scale = parseFloat(layer.dataset.scale);
  layer.style.transform = 'scale('+scale+')';
});

function parallaxHero(e){
  const mouseX = e.type.includes('touch') ? e.touches[0].clientX : e.clientX;
  const mouseY = e.type.includes('touch') ? e.touches[0].clientY : e.clientY;
  const heroH = this.offsetHeight;
  const heroW = this.offsetWidth;
  const heroMidX = this.offsetLeft + (heroW / 2);
  const heroMidY = this.offsetTop + (heroH / 2);
  const diffX = heroMidX - mouseX;
  const diffY = heroMidY - mouseY;
  
  layers.forEach(function(layer, index){
    const ratioX = parseFloat(layer.dataset.x);
    const ratioY = parseFloat(layer.dataset.y);
    const scale = parseFloat(layer.dataset.scale);
    const minScale = ((scale - 1) / 2);
    
    const minX = heroW * minScale;
    const minY = heroH * minScale;
    
    const maxX = - (heroW * minScale);
    const maxY = - (heroH * minScale);
    
    const moveX = Math.max(maxX,Math.min(minX,ratioX * diffX));
    const moveY = Math.max(maxY,Math.min(minY,ratioY * diffY));
    
    layer.style.left = moveX+'px';
    layer.style.top = moveY+'px';
    layer.style.transform = 'scale('+scale+')';
  });
}
              
            
!
999px

Console