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

              
                <!-- horizontal progress bars -->
<div class="progress-bar horizontal top"></div>
<div class="progress-bar horizontal bottom"></div>

<!-- vertical progress bars -->
<div class="progress-bar vertical left"></div>
<div class="progress-bar vertical right"></div>

<!-- display stuff, ignore below this line -->
<div class="display-content">
	<h1>Scrolling Progress Bars</h1>
</div>

<div class="scroll"></div>
              
            
!

CSS

              
                .progress-bar {
	display: block;
	width: 100%;
	height: 10px;
	position: fixed;
	z-index: 50;
	// this is the important line!
	// javascript controls the --scroll variable
	// "to right" can be changed to "to left" if you want to go the other way (example below)
	background: linear-gradient(to right, #CC9933 var(--scroll), transparent 0);
	background-repeat: no-repeat;
	
	&.horizontal.top {
		top: 0;
		left: 0;
	}
	
	&.horizontal.bottom {
		top: auto;
		bottom: 0;
		background: linear-gradient(to left, #CC9933 var(--scroll), transparent 0);
	}
	
	&.vertical.left {
		width: 10px;
		height: 100vh;
		top: 0;
		left: 0;
		background: linear-gradient(to bottom, #CC9933 var(--scroll), transparent 0);
	}
	
	&.vertical.right {
		width: 10px;
		height: 100vh;
		top: 0;
		right: 0;
		background: linear-gradient(to top, #CC9933 var(--scroll), transparent 0);
	}
}


// display stuff, ignore below this line
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@900&display=swap');

body {
	background: #2b2a26;
}

.display-content {
	display: flex;
	width: 100%;
	height: 100vh;
	align-items: center;
	justify-content: center;
	
	h1 {
		color: #fff;
		font-family: Montserrat, sans-serif;
		font-size: 34px;
		text-transform: uppercase;
	}
}

.scroll {
	height: 3000px;
}
              
            
!

JS

              
                var h = document.documentElement,
	 b = document.body,
	 st = 'scrollTop',
	 sh = 'scrollHeight',
	 htop = document.querySelector('.progress-bar.horizontal.top'),
	 hbot = document.querySelector('.progress-bar.horizontal.bottom'),
	 vleft = document.querySelector('.progress-bar.vertical.left'),
	 vright = document.querySelector('.progress-bar.vertical.right'),
	 scroll;

document.addEventListener('scroll', function() {
	console.log(h, b);
	// let's calculate the scroll position
	// ( body.scrollTop / ( body.scrollHeight - document.height ) ) * 100
	// multiplying by 100 here gives us a percent value
	scroll = ( h[st] || b[st] ) / ( ( h[sh] || b[sh] ) - h.clientHeight ) * 100;
	
	// set our variable for CSS to use
	htop.style.setProperty('--scroll', scroll + '%');
	hbot.style.setProperty('--scroll', scroll + '%');
	vleft.style.setProperty('--scroll', scroll + '%');
	vright.style.setProperty('--scroll', scroll + '%');
});
              
            
!
999px

Console