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 esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM 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.
.container
.container__header
%h1 Bouncy List
.container__description
Go on, add or remove items from the list and behold some sweet css animations
%input.list-input(type="text" placeholder="Add Todo" value="Take out the Trash")
%ul.list
- initial_notes = ["Buy Milk", "Get Haircut", "Take Dog for a Walk"]
- initial_notes.each do |a|
%li.list__item
#{a}
%i.icon-close
%footer
%a(href="https://twitter.com/code_dependant" class="twitter-follow-button" data-show-count="false")Follow @code_dependant
%script !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');
*
margin: 0
padding: 0
box-sizing: border-box
.cf
&:before
content: " "
display: table
&:after
content: " "
display: table
clear: both
*zoom: 1
$timing-function: ease-in-out
$duration: 1s
$delayRatio: 0.075s
$bounceLimitKeyframe: 30%
$bounceLimit: 50%
body
margin-top: 30px
background-color: #FFE181
color: #696969
font-family: 'Roboto Slab', sans-serif
font-size: 14px
h1
font-size: 48px
color: #927963
position: relative
display: inline-block
margin: 0
margin-bottom: .5rem
line-height: 1em
.container__header
text-align: center
.container__description
margin-bottom: 2.5em
text-align: center
.padded
padding: 1em
.container
width: 50%
@media(max-width: 500px)
width: 80%
margin: 10px auto
.pull-right
float: right
input
width: 100%
@extend .padded
box-shadow: inset 1px 1px 3px 0px rgba(134, 134, 134, 0.21)
border: 1px solid #C5C5C5
.list
list-style: none
.list__item--inserting
transform: translateY(-100%)
animation-name: slide-from-top
animation-timing-function: $timing-function
.list__item--inserting-new
transform: translateY(-200%) scaleY(1)
animation-name: slide-from-top--new
.list__item--inserting-removed
animation-name: slide-from-bottom--removed
.list__item--removing-sibling
animation-name: slide-from-bottom
.list__item
@extend .padded
margin-bottom: 0.5em
background-color: white
border: 1px solid #C5C5C5
border-radius: 3px
backface-visibility: hidden
box-shadow: 1px 1px 3px 0px rgba(134, 134, 134, 0.21)
animation-duration: $duration
animation-fill-mode: forwards
@for $i from 1 through 30
&:nth-child(#{$i})
animation-delay: $i * $delayRatio
z-index: $i
.icon-close
display: none
&:hover
.icon-close
display: block
.list__item--new
background-color: white
transform-origin: 50% 0
.list--removing
@for $i from 1 through 30
&:nth-child(#{$i})
animation-delay: $i * $delayRatio
z-index: $i
// keyframe animations
@keyframes slide-from-top
#{$bounceLimitKeyframe}
transform: translateY($bounceLimit)
100%
transform: translateY(0)
@keyframes slide-from-top--new
0%
background-color: white
10%
background-color: #D3EBD3
20%
background-color: #D3EBD3
#{$bounceLimitKeyframe}
transform: translateY($bounceLimit) scaleY(1)
100%
background-color: white
transform: translateY(0)
@keyframes slide-from-bottom
0%
transform: translateY(0)
100%
transform: translateY(-115%)
@keyframes slide-from-bottom--removed
0%
transform: translateY(0)
99.9%
transform: translateY(-115%)
opacity: 0
.list__item--inserting-removed
z-index: -1 !important
.hidden
position: absolute
footer
position: absolute
bottom: 12px
left: 20px
.icon-close
cursor: pointer
float: right
min-width: 16px
min-height: 16px
opacity: 0.5
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAADaGlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWx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0aW9uIFRpbWUAMjAxMjoxMToyNSAxODowMzoxMlUcr24AAACHSURBVDhP7ZPBCYAwDEWLBwfz5GCCIDiS2wiCI3jR/yWR2qYYwaMPnq1pEj00oUANOziL3DPmpod7ImNuVsiiRuSesSITjL/mkTWh4gNssr4hq9HOT9zy9A9SNCFOvopiSg3c/A0+aBCj17c932x4xhzzWlsDVHKAGRzXES7QKqI8Y46MdggHJ8M7/n0+sSMAAAAASUVORK5CYII=)
# no jQuery, just for "fun". It was no fun at all.
prefix = (->
styles = window.getComputedStyle(document.documentElement, "")
pre = (Array::slice.call(styles).join("").match(/-(moz|webkit|ms)-/) or (styles.OLink is "" and [
""
"o"
]))[1]
dom = ("WebKit|Moz|MS|O").match(new RegExp("(" + pre + ")", "i"))[1]
dom: dom
lowercase: pre
css: "-" + pre + "-"
js: pre[0].toUpperCase() + pre.substr(1)
)()
animationEndEvent = prefix.lowercase+"AnimationEnd"
animationEndEvent = "animationend" if prefix.lowercase is "moz"
console.log animationEndEvent
window.insertAnimation = (text, list)->
items = list.querySelectorAll(".list__item")
for item in list.querySelectorAll(".list__item")
item.classList.add("list__item--inserting")
item.addEventListener animationEndEvent, (event)->
event.target.classList.remove("list__item--inserting")
newItem = document.createElement("li")
newItem.classList.add "list__item"
newItem.classList.add "list__item--inserting-new"
newItem.innerHTML = text
closeIcon = document.createElement("i")
closeIcon.classList.add "icon-close"
newItem.appendChild closeIcon
closeIcon.addEventListener "click", itemClickHandler
firstItem = items[0]
list.insertBefore(newItem, firstItem)
newItem.addEventListener animationEndEvent, (event)->
event.target.classList.remove("list__item--inserting-new")
window.removeAnimation = (index, list)->
items = list.querySelectorAll(".list__item")
item = items.item(index)
item.classList.add("list__item--inserting-removed")
postItems = document.querySelectorAll(".list__item:nth-child(1n+#{(index+2)})")
postCount = 0
handler = (event)->
event.target.removeEventListener animationEndEvent, arguments.callee
postCount++
if postCount is postItems.length or postCount > 5
list.removeChild(item)
for removeItem in postItems
removeItem.classList.remove("list__item--removing-sibling")
for postItem in postItems
postItem.classList.add("list__item--removing-sibling")
postItem.addEventListener animationEndEvent, handler
if postItems.length is 0
item.addEventListener animationEndEvent, -> list.removeChild(item)
addListItem = ->
input = document.querySelectorAll(".list-input").item(0)
list = document.querySelectorAll(".list").item(0)
todoText = input.value
input.value = ""
if todoText isnt ""
insertAnimation(todoText, list)
removeListItem = (index)->
list = document.querySelectorAll(".list").item(0)
removeAnimation(index, list)
input = document.querySelectorAll(".list-input")[0]
input.addEventListener "keyup", (event)->
if event.keyCode is 13
addListItem()
itemClickHandler = (event)->
listItem = event.target.parentNode
event.target.removeEventListener "click", arguments.callee
itemsNodeList = document.querySelectorAll(".list .list__item")
itemsArray = Array.prototype.slice.call(itemsNodeList)
index = itemsArray.indexOf(listItem)
removeListItem(index)
for item in document.querySelectorAll(".list .list__item .icon-close")
item.addEventListener "click", itemClickHandler
input.style.marginBottom = String(input.offsetHeight)+"px"
setTimeout ->
addListItem()
, 1000
Also see: Tab Triggers