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 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

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

              
                <body>
  <h1>scroll to draw the SVG!</h1>
  <svg id="svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 -20 1595 500">
    <path id="line-art"
        d="M0,218.23H119.26l12.24-60.5,12,137,44-218,33,293,48-263h253v222h-211v-183h251v245.7h-217V218.23h333L749.75,146,654.5,50.73h95.25L1028.12,329.1,1166,191.23h-360l258,258L1332.5,180.73c-43.94-153.5,158.43-220.19,262.5-157" />  
</svg>
</body>
              
            
!

CSS

              
                body {
  height: 10000px;
  background: #b48f8f;
  margin: 0;
  padding: 0;
}

#line-art {
  fill: none;
  stroke: #fff44d;
  stroke-miterlimit: 10;
  stroke-width: 15px;
  stroke-linecap: round;
  
/* If you don't like the look of sharp corners    */
  stroke-linejoin: round;
}

#svg {
  position: fixed;
  left: 0;
}

h1 {
  font-size: 4rem;
  font-family: sans-serif;
  text-transform: uppercase;
  line-height: 1.1;
  margin: 0;
  margin-left: 2rem;
  border-bottom: 5px solid #fff44d;
  display: inline-block;
}
              
            
!

JS

              
                const lineart = document.getElementById('line-art');
const length = lineart.getTotalLength();

console.log(length);

// Turns the svg into a dashed line whose gap is as large as the svg itself. The "40" allows 40px of the svg to be visible at the start 
lineart.style.strokeDasharray = length;
lineart.style.strokeDashoffset = length - 40;

window.addEventListener("scroll", () => {
  let scrollpercent = 
(document.body.scrollTop + document.documentElement.scrollTop) /          (document.documentElement.scrollHeight - document.documentElement.clientHeight);
  
//   speedratio of 2 finishes the drawing halfway down the page.
  const speedratio = 2;
  let draw = length * scrollpercent * speedratio;
  
  // console.log ("draw", draw);
  
  let position = length - draw;
  
  //When position goes negative, the svg starts to "erase" itself
  if ( position > 0) {
    lineart.style.strokeDashoffset = position;
  }
  
  // console.log ("position", position);
  
});

              
            
!
999px

Console