css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <html>
  <head>
  </head>
  <body>

    <svg viewbox="0 0 890 1012" xmlns="http://www.w3.org/2000/svg" width="890" height="1012" class="rennen">
      <g transform="translate(80 91)">
        <g class="wrapper">
          <rect x="0" y="0" width="730" height="830" fill="#231f20"></rect>
          <g class="js-lines-1"></g>

          <g class="js-lines-2"></g>

          <g class="js-lines-3"></g>
        </g>
      </g>
    </svg>

    <div class="div"></div>
  </body>
</html>
            
          
!
            
              html,
body {
  margin: 0;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  
  height: 100vh;

  background: #00ddc3;
}

svg {
  width: 100%;
  height: 100%;

  transform: translate3d(0, 0, 0);

  transform-origin: 584px 173px;
  /*transform: translate3d(0, 0, 0) scale(10) rotate(79deg);*/

  /*transition-property: transform-origin, transform;
  transition-timing-function: linear;
  transition-duration: 5000ms;*/
}

.wrapper {
  transition-timing-function: linear;
}

.wrapper--last {
  transition-timing-function: ease-out;
}

.line {
  stroke:#00ddc3;
  stroke-width: 4px;
  fill: none;

  stroke-dasharray: 1200;
  stroke-dashoffset: 1200;
  /*animation: dash 200s linear forwards;*/

  /*transition-property: stroke-dashoffset;
  transition-timing-function: linear;
  transition-duration: 5000ms;*/
  transition-timing-function: linear;
  
  /*For crossing lines:*/
  /*stroke-dasharray: 800;*/
  /*stroke-dashoffset: 1000;*/
  
}

/*.line:nth-child(even) {
  animation: dash 200s linear forwards;
}

.line:nth-child(odd) {
  animation: dash-reverse 200s linear forwards;
}*/

@keyframes dash-reverse {
  from {
    stroke-dashoffset: -1000;
  }

  to {
    stroke-dashoffset: 0;
  }
}

@keyframes dash {
  from {
    stroke-dashoffset: 1000;
  }
  to {
    stroke-dashoffset: 0;
  }
}
            
          
!
            
              var Rennen = function() {
  // The duration at each phase. 
  var standardDuration = 5000;

  this.animationPhaseIndex_ = 0;

  this.currentAnimation_ = null;

  this.startTime_ = 0;

  this.svgElement_ = document.querySelector('.rennen');

  this.svgGroup_ = document.querySelector('.wrapper');

  this.lines_ = [];

  /**
   * Animation config, contains an array of objects which
   * contain the duration, from and to css rules.
   */
  this.animationConfig_ = [{
    // Phase 1
    duration: standardDuration,
    from: {
      transformOrigin: '90px 320px',
      transform: 'rotate(270deg) scale(12)',
      strokeDashoffset: 1150
    },
    to: {
      strokeDashoffset: 1100
    }
  }, {
    // Phase 2
    duration: standardDuration,
    
    from: {
      transformOrigin: '475px 220px',
      transform: 'scale(12)',
      strokeDashoffset: 920,
    },
    to: {
      strokeDashoffset: 870,
      transform: 'scale(12) rotate(-10deg)'
    }
  }, {
    // Phase 3
    duration: standardDuration,
    
    from: {
      transformOrigin: '670px 475px',
      transform: 'scale(10)',
      strokeDashoffset: 590,
    },
    to: {
      strokeDashoffset: 550,
      transform: 'scale(10) translate(10px, 0)',
    }
  }, {
    // Phase 4
    duration: standardDuration,
    
    from: {
      transformOrigin: '428px 677px',
      transform: 'scale(12) translate(0,0)',
      strokeDashoffset: 291,
    },
    to: {
      transform: 'scale(10) rotate(-10deg) translate(20px, 20px)',
      strokeDashoffset: 201
    }
  }, {
    // Phase 5
    duration: standardDuration,
    
    from: {
      transformOrigin: '350px 350px',
      transform: 'scale(10) translate(0,0)',
      strokeDashoffset: 670
    },
    to: {
      transform: 'scale(8) translate(0, -20px)',
      strokeDashoffset: 590
    }
  }, {
    // Phase 6
    duration: standardDuration,
    
    from: {
      transformOrigin: '635px 444px',
      transform: 'scale(10) rotate(240deg)',
      strokeDashoffset: 620
    },
    to: {
      transform: 'scale(8) rotate(230deg)',
      strokeDashoffset: 560
    }
  }, {
    // Phase 7
    duration: standardDuration,
    
    from: {
      transformOrigin: '585px 200px',
      transform: 'scale(8) rotate(50deg)',
      strokeDashoffset: 960
    },
    to: {
      transform: 'scale(5) rotate(0)',
      strokeDashoffset: 670
    }
  }, {
    // Phase 8
    duration: 8000,
    
    from: {
      transformOrigin: '440px 735px',
      transform: 'scale(3) translateX(-50px) rotate(-30deg)',
      strokeDashoffset: 580
    },
    to: {
      transform: 'scale(1)',
      strokeDashoffset: 1
    }
  }];

  this.init();
};

/**
 * Get each group and create the paths, calculate the
 * start times and start the animation.
 */
Rennen.prototype.init = function() {
  // Lines 1
  var group = document.querySelector('.js-lines-1');
  var points = [{
    x: 128,
    y: 0
  }, {
    x: 730,
    y: 625
  }];

  this.createPaths_(group, points, 'x');

  // Lines 2
  group = document.querySelector('.js-lines-2');
  points = [{
    x: 0,
    y: 200
  }, {
    x: 610,
    y: 830
  }];

  this.createPaths_(group, points, 'y');


  // Lines 3
  group = document.querySelector('.js-lines-3');
  points = [{
    x: 353,
    y: 0
  }, {
    x: 515,
    y: 193
  }, {
    x: 265,
    y: 355
  }, {
    x: 457,
    y: 556
  }, {
    x: 204,
    y: 830
  }];

  this.createPaths_(group, points, 'x');

  for (var i = 0; i < this.animationConfig_.length; i++) {
    this.animationConfig_[i].startTime = this.calculateStartTime_(i);
  }

 this.setupAnimation_();

};


/**
 * Send an array of coordinates, and create the paths 15 times,
 * offset by a certain amount to create the effect.
 */
Rennen.prototype.createPaths_ = function(parent, points, direction) {
  var strokeWidth = 4;
  var spaceBetween = 6 + strokeWidth;
  var numLines = 15;
  var className = 'line';

  for (var i = 0; i < numLines; i++) {
    var path = document.createElementNS("http://www.w3.org/2000/svg", 'path'); //Create a path in SVG's namespace
    var x = points[0].x + ((direction === 'x') ? (spaceBetween * i) : 0);
    var y = points[0].y + ((direction === 'y') ? (spaceBetween * i) : 0);
    var pathD = 'M ' + x + ' ' + y + ' ';

    for (var j = 1; j < points.length; j++) {
      x = points[j].x + ((direction === 'x') ? (spaceBetween * i) : 0);
      y = points[j].y + ((direction === 'y') ? (spaceBetween * i) : 0);
      pathD += 'L ' + x + ' ' + y + ' ';
    }

    path.setAttribute('d', pathD);
    path.classList.add(className);

    parent.appendChild(path);

    this.lines_.push(path);
  }
};



/**
 * Store the start time, initiate the update loop and
 * start the first animation phase.
 */
Rennen.prototype.setupAnimation_ = function() {
  this.startTime_ = performance.now();
  this.startNextPhase_(this.animationPhaseIndex_);
  this.update_();
  
};


/**
 * Grab the next animation phase and apply the from and to styles,
 * along with setting the transition durations.
 */
Rennen.prototype.startNextPhase_ = function(phaseIndex) {
  // TODO animation.startTime = calculateStartTime.

  if (phaseIndex === this.animationConfig_.length - 1) {
    this.svgGroup_.classList.add('wrapper--last');
  }

  var phase = this.animationConfig_[phaseIndex];

  // Set transition time to 0.
  this.svgGroup_.style.transitionDuration = 0 + 'ms';
  this.setStyleOnLines_({
    'transitionDuration': 0 + 'ms'
  });

  // Apply start rules to container and lines
  if (phase.from.transformOrigin) {
    this.svgGroup_.style.transformOrigin = phase.from.transformOrigin;
  }
  
  if (phase.from.transform) {
    this.svgGroup_.style.transform = phase.from.transform;
  }

  if (phase.from.strokeDashoffset) {
    this.setStyleOnLines_({
      strokeDashoffset: phase.from.strokeDashoffset
    });
  }
 
  requestAnimationFrame(function() {
    // Apply duration transition time.
    this.svgGroup_.style.transitionDuration = phase.duration + 'ms';

    this.lines_.forEach(function(line) {
      var duration = Math.round(phase.duration + Math.random() * 4000);
      line.style.transitionDuration = duration + 'ms';
    });

    // Apply transforms and transform origin to container svg
    if (phase.to.transformOrigin) {
      this.svgGroup_.style.transformOrigin = phase.to.transformOrigin;
    }
    
    if (phase.to.transform) {
      this.svgGroup_.style.transform = phase.to.transform;
    }
    
    
    // Apply dash offset to lines.
    if (phase.to.strokeDashoffset) {
      this.setStyleOnLines_({
        strokeDashoffset: phase.to.strokeDashoffset
      });
    }
  }.bind(this));
  
  

  this.animationPhaseIndex_ = phaseIndex;
  this.currentAnimation_ = phase;
};


/**
 * Loop through all of the <path> elements and set the style rules.
 */
Rennen.prototype.setStyleOnLines_ = function(rules) {
  this.lines_.forEach(function(line) {
    for(styleProp in rules) {
      line.style[styleProp] = rules[styleProp];
    }
  });
};


/**
 * Calculate the start time of a phase by looping through the previous phases
 * and adding up the duration.
 */
Rennen.prototype.calculateStartTime_ = function(phaseIndex) {
  var startTime = 0;

  for (var i = 0; i < phaseIndex; i++) {
    startTime += this.animationConfig_[phaseIndex].duration;
  }

  return startTime;
};


/**
 * Update run every frame. Check the current time against the 
 * start time to calculate whether to move onto the next
 * animation phase or end the animation entirely.
 */
Rennen.prototype.update_ = function() {

  var currentTime = performance.now();
  var time = currentTime - this.startTime_;
  var endAnimation = false;

  if (time >= this.currentAnimation_.startTime + this.currentAnimation_.duration) {
    if (this.animationPhaseIndex_ + 1 >= this.animationConfig_.length) {
      // End animation
      endAnimation = true;
    } else {
        this.startNextPhase_(this.animationPhaseIndex_ + 1);  
    }
  }

  if (!endAnimation) {
    requestAnimationFrame(this.update_.bind(this));
  }
};


(function() {
  var rennen = new Rennen();
})();
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console