123

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.

            
              <header>
	I'm a header, beep boop.
</header>

<main>
	<h1>Article title yay \o/</h1>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p>

	<p>The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.</p>
	
	<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p>

	<p>The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.</p>

<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p>

	<p>The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.</p>
	
	<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p>

	<p>The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.</p>
	
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p>

	<p>The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.</p>
	
	<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p>

	<p>The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.</p>
	
</main>

<aside>
	<h2>Subscribe now!</h2>
	<input type="email"/>
	<button>Subscribe</button>
</aside>
            
          
!
            
              // The Timed newsletter popup will only appear if the user has scrolled down at least 50 percent and has been on the page for 30 seconds

// Could add the [data-site-visit-duration] attribute to make sure the user has been on the site for a while

// Timed newsletter popup
html[data-vertical-scroll-progress~='50'][data-page-visit-duration~="30"] aside {
	position: fixed;
	width:18em;
	height:8em;
	max-height:80vh;
	padding:2em;
	left:calc(50% - 9em);
	top:calc(50% - 5em);
	background:#fff;
	box-shadow:0 .25em 1em rgba(0,0,0,.5);
}

aside {
	padding:0 1em 2em;
}

// Floating header logic
header {
	width: 100%;
  min-height: 3em;
  background-color: #eee;
}

html:not([data-vertical-scroll='0']) {
	
	body {
	  padding-top: 3em;
	}
	
	header {
		position: fixed;
		top: 0;
		background-color: #fff;
		box-shadow: 0 0 .5em rgba(0, 0, 0, .5);
	}
	
}


// Cosmetics
header {
	box-sizing: border-box;
	padding: 1em;
	transition: background-color .25s;
}

main {
	padding:0 1em;
}
            
          
!
            
              // Clear console so we our console is clutter free before we start
console.clear();


// The debounce function receives our function as a parameter
const debounce = (fn) => {

  // This holds the requestAnimationFrame reference, so we can cancel it if we wish
  let frame;

  // The debounce function returns a new function that can receive a variable number of arguments
  return (...params) => {
    
    // If the frame variable has been defined, clear it now, and queue for next frame
    if (frame) { 
      cancelAnimationFrame(frame);
    }

    // Queue our function call for the next frame
    frame = requestAnimationFrame(() => {
      
      // Call our function and pass any params we received
      fn(...params);
    });

  } 
};

// Returns an array of steps from value to 0
const stack = (value, step) => {
	value = Math.floor(value / step) * step;
	const parts = [value];
	while (value > 0) {
		value -= step;
		parts.push(value);
	}
	return parts.reverse();
}

// Creates an environment store at a certain element
const createEnvStore = (props, root = document.documentElement) => {
	const data = root.dataset;
	const sync = () => {
		Object.entries(props).forEach(([key, value]) => {
			data[key] = Array.isArray(value) ? value.join(' ') : value;
		})
	}
	sync();
	return (key, value) => {
		props[key] = value;
		sync();
		console.log(data);
	}
};

// Set default environment parameters
const updateEnv = createEnvStore({
	'verticalScroll': window.scrollY,
	'verticalScrollProgress': 0,
	'pageVisitDuration': 0,
	'siteVisitDuration': 0
});

// Listen for new scroll events, here we debounce our scroll handler function for performance reasons
document.addEventListener('scroll', debounce(() => {
	
	const scrollOffset = window.scrollY;
	const pageHeight = document.documentElement.scrollHeight - window.innerHeight;
	const scrollProgress = Math.min(1, scrollOffset / pageHeight);
	
	// Set current scroll offset (we use this to make the floating header)
	updateEnv('verticalScroll', scrollOffset);
	
	// Calculate current progress in percentages
	updateEnv('verticalScrollProgress', stack(Math.round(scrollProgress * 100), 5));
	
}), { passive: true });


// Determine How long has the user been on the page, updates the `pageVisitDuration` each 15 seconds, the siteVisitDuration is set in minutes.
const pageOpenDate = Date.now();

// Retrieves the site visit duration, or, if not defined, 0
const siteVisitDuration = parseInt(localStorage.getItem('siteVisitDuration') || 0, 10);

// Set current amount of visits
updateEnv('siteVisitDuration', stack(siteVisitDuration / 60, 1));

// Update each 15 seconds
setInterval(() => {
	// Page visit duration in seconds
	const pageVisitDuration = Math.round(Date.now() - pageOpenDate) / 1000;
	
	// Update `pageVisitDuration` with 15 second intervals (0 15 30 45 ...)
	updateEnv('pageVisitDuration', stack(pageVisitDuration, 15));
	
	// Update `siteVisitDuration` with 1 minute intervals (0 1 2 3 ...)
	updateEnv('siteVisitDuration', stack((siteVisitDuration + pageVisitDuration) / 60, 1));

	// Remember current duration
	localStorage.setItem('siteVisitDuration', siteVisitDuration + pageVisitDuration);
	
}, 15000);
            
          
!
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.

Console