HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs 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 its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<!-- <div class="fixed"></div> -->
<div class="container">
<ul class="section one is-released">
<li>panel</li>
<li>content</li>
<li>content</li>
<li>content</li>
<li>content</li>
<li>content</li>
</ul>
<div class="section two">
<div class="content">panel</div>
</div>
<div class="section three">
<div class="content">panel</div>
</div>
<div class="section four">
<div class="content">panel</div>
</div>
<div class="section five">
<div class="content">panel</div>
</div>
</div>
body{
margin: 0;
padding: 0;
}
.fixed{
position: fixed;
z-index: 0;
top: 0;
left: 0;
width: 100%;
height: 200px;
background-image: url(https://images.unsplash.com/photo-1500122710449-d384ebf0891a?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&s=1df2a3596d28b4e9559c4feed0cedf41);
}
*{box-sizing: border-box;}
.container{
transition: 300ms ease ;
}
.section{
width: 100%;
position: fixed;
box-shadow: inset 0 0 0 5px ghostwhite;
min-height: 600px;
color: white;
list-style: none;
padding: 25px;
}
.is-released{
position: relative!important;
}
// UI pattern I'm working on for a client project. Thought I'd share :)
// Gonna be porting this over to a react component in the near future, so be on the lookout for that
// Still working on this, but here's a plain ol javascript way of having a fun fixed-then-scrolling panel ui
// Far as I can tell, this works in Safari, Chrome, Firefox
/* Pretty mobile friendly, too. Only problem is fixed position bug when scrolling in a mobile
browser and the window shrinks, but the panels don't resize accordingly. I'm looking at window
resize handler to see if that can alleviate the problem. 🎉
*/
var colors=['rebeccapurple','blanchedalmond','mistyrose','goldenrod','dodgerblue','palegoldenrod']
var container = document.querySelector('.container')
var currentIndex = 0
var activePanel = null
var config ={
scrollItems:[],
container:null,
children: null,
lastScrollTop:0,
direction: 'down'
}
var createScrollSystem = function(accumulator, node) {
if(node){
var children = node.children
for(var i=children.length-1; i>=0; i--){
var height = children[i].getBoundingClientRect().height
accumulator=accumulator+height+Math.ceil(window.innerHeight*.75 - (i*-50) )
var scrollItem = {
height: Math.ceil(height)
, scrollHeight: Math.ceil(accumulator)
, spaceFromTop: Math.ceil(window.innerHeight*.75 - (-i*-50) )
}
config.scrollItems.push(scrollItem)
children[i].style.top=`${scrollItem.spaceFromTop}px`
children[i].style.marginBottom=`${scrollItem.spaceFromTop}px`
children[i].style.zIndex=-i+10
children[i].style.backgroundColor=colors[i]
}
node.style.height=`${Math.ceil(config.scrollItems[config.scrollItems.length-1].scrollHeight+window.innerHeight)}px`
config.container=node
config.children=children
activePanel=config.children[0]
}
}
createScrollSystem(0,container)
function handleScroll(e){
var length = config.children.length-1
//handle scroll direction
var s=window.scrollY
if(s < config.lastScrollTop){config.direction='up'}
else{config.direction='down'}
config.lastScrollTop=s
//handle panel behavior while user scrolls DOWN the page
if(config.direction==='down'){
var scrollIndex=0
scrollIndex=currentIndex
if(
scrollIndex < length &&
config.children[scrollIndex] === activePanel &&
config.children[scrollIndex].getBoundingClientRect().bottom <= 0 ){
scrollIndex+=1
config.children[scrollIndex].classList.add('is-released')
currentIndex=scrollIndex
activePanel=config.children[currentIndex]
}
}
//handle panel behavior while user scrolls UP the page
if(config.direction==='up'){
scrollIndex=currentIndex
if(
scrollIndex > 0 &&
currentIndex > 0 &&
config.children[scrollIndex] === activePanel &&
config.children[scrollIndex].getBoundingClientRect().top - config.scrollItems[length - scrollIndex].spaceFromTop >= 0 ){
config.children[scrollIndex].classList.remove('is-released')
scrollIndex-=1
currentIndex=scrollIndex
activePanel=config.children[currentIndex]
}
}
//handle background color of container
container.style.backgroundColor=colors[currentIndex]
if(config.children[length].getBoundingClientRect().bottom <= 0){container.style.backgroundColor='ghostwhite'}
}
window.addEventListener('scroll', function(e){handleScroll(e)})
/* This down here needs to be cleaned up 👇
============================================ */
// class ScrollItem {
// constructor(height, scrollHeight, spaceFromTop) {
// this.height = height
// this.scrollHeight = scrollHeight
// this.spaceFromTop = spaceFromTop
// }
// newScrollHeight(newHeight){ this.scrollHeight = newHeight }
// }
// const CONTAINER = document.querySelector('.container') //the element holding the panels we want to scroll
// const SCROLL_ITEM_NODES = Array.from( document.querySelectorAll('.menu-container') ) //make an array from the supplied dom elements
// let scrollItems = [] //array to store our new acrollItems created with SCROLL_ITEM_NODES
// let currentScrollIndex = 0 //current index of active panel
// let lastScrollTop = 0 //fulcrum to determine scroll direction
// let totalPanelHeight = 0 //height of all panels passed into the view
// let createScrollSystem = null //store a null value for our function to create scrollItems
// let topSpace = null
// //Ok, let's get down to business:
// // 1. here's our function to generate the ScrollItems
// // we're going to use this function when the page loads, then re-use it if the user updates the page height
// createScrollSystem = function(accumulator, nodes, arr) {
// for(let i in nodes){
// let height = nodes[i].getBoundingClientRect().height
// let width = nodes[i].getBoundingClientRect().width
// accumulator=accumulator+height+Math.ceil(window.innerHeight*.5 - (i*-40) )
// let scrollItem = new ScrollItem(
// Math.ceil(height),
// Math.ceil(accumulator),
// Math.ceil(window.innerHeight*.5 - (i*-40) )
// )
// arr.push(scrollItem)
// nodes[i].style.paddingTop=`${scrollItem.spaceFromTop}px`
// }
// CONTAINER.style.height=`${Math.ceil(scrollItems[scrollItems.length-1].scrollHeight+window.innerHeight)}px`
// return arr
// }
// // 2. let's make those ScrollItems
// createScrollSystem(0,SCROLL_ITEM_NODES,scrollItems)
// // console.log(scrollItems)
// // console.log('CONTAINER style height: ',CONTAINER.style.height)
// console.log(document.body.clientHeight)
// // 4. and let's make sure our objects stay in the right place if the user resizes the window
// let initialWindowHeight = window.innerHeight
// let initialWindowWidth = window.innerWidth
// function resizeWindow(e){
// let height = window.innerHeight
// let width = window.innerWidth
// if(height > initialWindowHeight || height < initialWindowHeight) {
// createScrollSystem(0,SCROLL_ITEM_NODES,scrollItems)
// // console.log('CONTAINER height: ',CONTAINER.style.height, 'scroll height: ',document.documentElement.scrollHeight)
// }
// if(width > initialWindowWidth || width < initialWindowWidth) {
// // console.log("we're changing the width of the window")
// }
// // set the initial window values to the new values
// initialWindowHeight = window.innerHeight
// initialWindowWidth = window.innerWidth
// }
// // 5. now let's do some stuff when the user scrolls the page
// currentScrollIndex = 0
// SCROLL_ITEM_NODES[currentScrollIndex].classList.add('is-released')
// function scrollPanels(e) {
// let scrollDistance = window.pageYOffset || document.documentElement.scrollTop
// console.log( Math.ceil(scrollDistance) + window.innerHeight, Math.ceil( CONTAINER.getBoundingClientRect().height ) )
// // console.log( Math.ceil( CONTAINER.getBoundingClientRect().height ) - Math.ceil(st) )
// // if(st>scrollItems[0].scrollHeight){console.log('0 is outta view')}
// // if(st>scrollItems[1].scrollHeight){console.log('1 is outta view')}
// // if(st>scrollItems[2].scrollHeight){console.log('2 is outta view')}
// console.log(scrollItems[0].scrollHeight)
// // if (st > lastScrollTop){console.log()}
// // else {console.log()}
// // lastScrollTop = st //update lastScrollTop so we know which direction we're scrolling when the user changes directions
// }
// window.addEventListener('scroll', _.throttle(scrollPanels, 100), false);
// window.addEventListener('resize', _.throttle(resizeWindow, 1000), false);
Also see: Tab Triggers