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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                svg.mask(xmlns='http://www.w3.org/2000/svg', viewbox='0 0 100 50', preserveAspectRatio='none')
  polygon.poly#mask0(points='0,0 100,0 100,50 0,50')
  polygon.poly.hidden#mask1(points='0,0 50,0 100,50 0,50')
  polygon.poly.hidden#mask2(points='0,0 50,0 50,50 0,50')
  polygon.poly.hidden#mask3(points='0,0 50,0 0,50 0,50')
  polygon.poly.hidden#mask4(points='0,0 50,0 0,0 0,0')
  polygon.poly.poly--red#red0(points='100,0 100,0 100,50 100,50')
  polygon.poly.poly--red.hidden#red1(points='50,0 100,0 100,50 50,50')
  polygon.poly.poly--red.hidden#red2(points='0,0 100,0 100,50 0,50')
  
- for(var i = 0; i < 100; i++)
  p= i

              
            
!

CSS

              
                html
  width: 100%
  height: 100%
  touch-action: manipulation
  color: transparent
  background-color: gray
  font-size: 1em
  line-height: 1.4

body
  font-family: 'Abel', sans-serif
  width: 100%
  height: 100%
  margin: 0
  padding: 0

.mask
.red
	position fixed
	top 0
	left 0
	width 100%
	height 100%
	> .poly
		perspective 600
		fill white
		width 100%
		height 100%
		&--red
			fill red
      
.hidden
  visibility: hidden
  display: none

              
            
!

JS

              
                var html = document.documentElement;
var body = document.body;
var scrollPercent = 0;
var ticking = false;
var tl;
var poly;

var isCSS1Compat = ((document.compatMode || '') === 'CSS1Compat');
function getScrollY() {
	return this.scrollY
	// return this.pageYOffset || isCSS1Compat ? html.scrollTop : body.scrollTop;
}

function getDocHeight() {
	return Math.max(
		body.scrollHeight,
		body.offsetHeight,
		html.clientHeight,
		html.scrollHeight,
		html.offsetHeight
	);
}

function updateInfo() {
	console.log('updateInfo', Number(tl.progress().toFixed(2)), tl.duration());
}

function updateScrollHandler(event) {
	var scrollY = getScrollY();
	var docHeight = getDocHeight();
	var winHeight = window.innerHeight;
	scrollPercent = scrollY / (docHeight - winHeight)
	scrollPercent = scrollPercent >= 0 ? scrollPercent : 0;
  tl.progress(scrollPercent).pause();
}

window.addEventListener('scroll', function () {
  if (!ticking) {
		window.requestAnimationFrame(function () {
			updateScrollHandler();
			ticking = false;
		});
	}
	ticking = true;
});

poly = {
	mask: document.getElementById('mask0'),
	red: document.getElementById('red0')
};

tl = new TimelineLite({
	onUpdate: updateInfo,
	paused: true
});

tl
	.to(poly.mask, 1, {morphSVG: "#mask1"})
	.to(poly.mask, 1, {morphSVG: "#mask2"})
	.to(poly.mask, 1, {morphSVG: "#mask3"})
	.to(poly.mask, 1, {morphSVG: "#mask4"})
	.to(poly.red, 1, {morphSVG: "#red1"})
	.to(poly.red, 1, {morphSVG: "#red2"});

updateScrollHandler();
              
            
!
999px

Console