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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <!DOCTYPE html>
<html lang='en'>

<head>
	<meta class="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<title>Scroll Animations</title>
	<link rel='stylesheet' href='css/style.css' />
</head>

<body>
	<h1>Scroll Animations</h1>
	<svg id="female-svg" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 36 36" enable-background="new 0 0 36 36" xml:space="preserve">
    <defs>
      <linearGradient id="gradient-1" x1="0%" y1="0%" x2="0%" y2="100%">
        <stop offset="0%" stop-color="#00c9ff" />
        <stop offset="100%" stop-color="#92fe9d" />
      </linearGradient>
    </defs>
    <path id="female-path" fill-opacity="0.3" stroke="url(#gradient-1)" stroke-width="2" stroke-linejoin="round" stroke-miterlimit="10" d="M22.2,24.6 c0-0.2,0-0.6-0.1-1c3.7-0.4,6.2-1.2,6.2-2.2c0,0,0,0,0-0.1c-2.7-2.4,2.4-19.7-7.1-19.4C20.6,1.4,19.5,1,18,1 C5.2,2,10.9,18.3,7.9,21.4l0,0c0,0,0,0,0,0l0,0l0,0c0,1,2.5,1.8,6,2.2c0,0.2,0,0.5-0.1,1C12.4,28.5,2.5,27.4,2,35h32 C33.5,27.4,23.6,28.5,22.2,24.6z" />
  </svg>
	<svg version="1.1" id="male-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 36 36" enable-background="new 0 0 36 36" xml:space="preserve">
    <defs>
      <linearGradient id="gradient-2" x1="0%" y1="0%" x2="0%" y2="100%">
        <stop offset="0%" stop-color="#fc00ff" />
        <stop offset="100%" stop-color="#00dbde" />
      </linearGradient>
    </defs>
    <path id="male-path" fill-opacity="0.3" stroke="url(#gradient-2)" stroke-width="2" stroke-linejoin="round" stroke-miterlimit="10" d="M22.1,24.6 c-0.1-1.3-0.1-2.3-0.1-3.5c0.6-0.3,1.7-2.4,1.9-4.1c0.5,0,1.2-0.5,1.5-2.4c0.1-1-0.4-1.6-0.6-1.7c0.8-2.4,2.4-9.6-3-10.4 c-0.6-1-2-1.5-3.8-1.5c-7.4,0.1-8.3,5.6-6.7,11.9c-0.3,0.2-0.8,0.7-0.6,1.7c0.2,1.9,1,2.3,1.5,2.4c0.2,1.7,1.3,3.8,1.9,4.1 c0,1.2,0,2.2-0.1,3.5C12.4,28.5,2.5,27.4,2.1,35h31.8C33.5,27.4,23.6,28.5,22.1,24.6z" />
  </svg>
	<script src="js/main.js"></script>
</body>

</html>
              
            
!

CSS

              
                body {
	height: 5000px;
	background: #833ab4; /* fallback for old browsers */
	background: -webkit-linear-gradient(
		to bottom,
		#fcb045,
		#fd1d1d,
		#833ab4
	); /* Chrome 10-25, Safari 5.1-6 */
	background: linear-gradient(
		to bottom,
		#fcb045,
		#fd1d1d,
		#833ab4
	); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
}

h1 {
	font-family: sans-serif;
	font-weight: 300;
	color: ghostwhite;
	text-transform: uppercase;
	text-align: center;
	font-size: 40px;
	letter-spacing: 1px;
	font-weight: 600;
	padding: 25px 15px;
}

#female-svg,
#male-svg {
	position: fixed;
	top: 50%;
	width: 150px;
	height: 150px;
	margin: -75px 0 0 -75px;
}

#female-svg {
	left: 25%;
}

#male-svg {
	left: 75%;
}

              
            
!

JS

              
                // inspiration: https://codepen.io/chriscoyier/pen/YXgWam
// Get a reference to the <path>
var path = document.querySelector("#female-path");
var malePath = document.querySelector("#male-path");
// Get length of path... ~577px in this case
var pathLength = path.getTotalLength();
var malePathLength = malePath.getTotalLength();
// Make very long dashes (the length of the path itself)
path.style.strokeDasharray = pathLength + " " + pathLength;
malePath.style.strokeDasharray = malePathLength + " " + malePathLength;
// Offset the dashes so the it appears hidden entirely
path.style.strokeDashoffset = pathLength;
malePath.style.strokeDashoffset = malePathLength;
// Jake Archibald says so
// https://jakearchibald.com/2013/animated-line-drawing-svg/
path.getBoundingClientRect();
malePath.getBoundingClientRect();
// When the page scrolls...
window.addEventListener("scroll", function(e) {
	// What % down is it?
	// https://stackoverflow.com/questions/2387136/cross-browser-method-to-determine-vertical-scroll-percentage-in-javascript/2387222#2387222
	// Had to try three or four differnet methods here. Kind of a cross-browser nightmare.
	var scrollPercentage =
		(document.documentElement.scrollTop + document.body.scrollTop) /
		(document.documentElement.scrollHeight -
			document.documentElement.clientHeight);
	// Length to offset the dashes
	var drawLength = pathLength * scrollPercentage;
	var maleDrawLength = malePathLength * scrollPercentage;
	// Draw in reverse
	path.style.strokeDashoffset = pathLength - drawLength;
	malePath.style.strokeDashoffset = malePathLength - maleDrawLength;
	// When complete, remove the dash array, otherwise shape isn't quite sharp
	// Accounts for fuzzy math
	if (scrollPercentage >= 0.99) {
		path.style.strokeDasharray = "none";
		malePath.style.strokeDasharray = "none";
	} else {
		path.style.strokeDasharray = pathLength + " " + pathLength;
		malePath.style.strokeDasharray = malePathLength + " " + malePathLength;
	}
});

              
            
!
999px

Console