jqueryhtmlcsssvgskrollr

Recreating a parallax zoom effect with SVG Image mask


I'm trying to recreate the effect found at the bottom of this page where the words "REFORM CO" Zoom in to reveal a background image with a headline.

I attempted to recreate this effect myself using skrollr but I've hit a wall. ideally I'd like the SVG to be smaller and centered in the mask and for the video to stay fixed until the mask disappears just like the REFORM CO example.

Here's my HTML and the link to my attempt: https://jsfiddle.net/uex526qs/1/

<body>

<div class="knockout">

  <svg x="50%" y="100%" class="knockout-text-container"  height="100%" data-0="opacity:1;transform: scale(1);" data-50p="opacity:0;font-size: 10em;transform: scale(10);">

    <rect class="knockout-text-bg" width="100%" height="100%" fill="#fff" x="0" y="0" fill-opacity="1" mask="url(#knockout-text)"/>

    <mask id="knockout-text">
      <rect width="100%" height="100%" fill="#fff" x="0" y="0"  />

      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 97.73 97.73"><defs><style>.cls-1{fill:#000;}</style></defs><title>shape2</title><g id="Layer_2" data-name="Layer 2"><g id="Content"><path class="cls-1" d="M48.86,97.73A7.72,7.72,0,0,1,41.15,90V7.72a7.72,7.72,0,1,1,15.43,0V90A7.72,7.72,0,0,1,48.86,97.73Z"/><path class="cls-1" d="M90,56.58H7.72a7.72,7.72,0,1,1,0-15.43H90a7.72,7.72,0,1,1,0,15.43Z"/></g></g></svg>


    </mask>

  </svg>

</div>


<video autoplay muted loop id="myVideo">
<source src="http://thenewcode.com/assets/videos/ocean-small.mp4" type="video/mp4">
</video>


</body>

Any help is appreciated


Solution

    1. You can make an element stay fixed relative to the browser window using position: fixed.

    2. To make your mask scale relative to the element it is aplied to, use:

      <mask maskContentUnits="objectBoundingBox">
      

      then use coordinates in the range 0..1. That's the reason my scale() values are so small. Your shape is roughly 100x100, so I needed to scale by an extra 0.01 to get them down into the 0..1 range.

    The rest of your example was more-or-less correct.

    $(document).ready(function() {
      var s = skrollr.init();
      constants: {
        //fill the box for a "duration" of 150% of the viewport (pause for 150%)
        //adjust for shorter/longer pause
        knockout: '150p'
      }
    })
    html, body {
      position: relative;
      margin: 0;
      height: 1500px;
    }
    
    .container {
      position: fixed;
    }
    
    video {
      width: 100%;
    }
    
    .overlay {
      display: block;
      position: absolute;
      width: 100%;
      height: 100%;
      top: 0;
    }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/skrollr/0.6.30/skrollr.min.js"></script>
    
    <div class="container">
    
      <video autoplay muted loop id="myVideo">
        <source src="http://thenewcode.com/assets/videos/ocean-small.mp4" type="video/mp4">
      </video>
    
      <svg class="overlay" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid slice">
        <defs>
          <mask id="knockout" maskContentUnits="objectBoundingBox">
            <rect x="0" y="0" width="1" height="1" fill="white"/>
            <g fill="black"
               data-0="transform: translate(0.5px,0.5px) scale(0.0015) translate(-49px,-49px);"
               data-50p="transform: translate(0.5px,0.5px) scale(0.04) translate(-49px,-49px);">
              <path d="M48.86,97.73A7.72,7.72,0,0,1,41.15,90V7.72a7.72,7.72,0,1,1,15.43,0V90A7.72,7.72,0,0,1,48.86,97.73Z"/>
              <path class="cls-1" d="M90,56.58H7.72a7.72,7.72,0,1,1,0-15.43H90a7.72,7.72,0,1,1,0,15.43Z"/>
            </g>
          </mask>
        </defs>
        <rect x="0" y="0" width="100" height="100" fill="white" mask="url(#knockout)"/>
      </svg>
    
    </div>