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.
.cash-register
.cash-register__total-wrap
.cash-register__total
.cash-register__loop
.cash-register__loop-track(v-bind:style="{'--trans': lines % 10}")
- for(let c = 0; c < 10; c++)
sup= c
.cash-register__loop $
- for(let i = 0; i < 2; i++)
.cash-register__loop
.cash-register__loop-track(v-bind:style=`{'--trans': amount[${i}]}`)
- for(let c = 0; c < 10; c++)
div= c
.cash-register__loop .
- for(let i = 2; i < 4; i++)
.cash-register__loop
.cash-register__loop-track(v-bind:style=`{'--trans': amount[${i}]}`)
- for(let c = 0; c < 10; c++)
sup= c
.cash-register__mid
.cash-register__receipt-feed
.cash-register__receipt-container
ul.cash-register__receipt(v-bind:style="{'--trans': showLines}")
li.cash-register__receipt-item(v-for="l in receiptLines", :class="subbing ? 'subby' : 'hello'")
.cash-register__key
.cash-register__keypad-wrap
.cash-register__keypad
- for(let c = 0; c < 3; c++)
button.cash-register-key.cash-register-key--big-dollar(class=`${c === 0 ? 'cash-register-key--top' : ''}`, data-amount-index="0", v-on:click="addToLine")
button.cash-register-key.cash-register-key--big-dollar(class=`${c === 0 ? 'cash-register-key--top' : ''}`, data-amount-index="1", v-on:click="addToLine")
button.cash-register-key(class=`${c === 0 ? 'cash-register-key--top' : ''}`, data-amount-index="2", v-on:click="addToLine")
button.cash-register-key(class=`${c === 0 ? 'cash-register-key--top' : ''}`, data-amount-index="3", v-on:click="addToLine")
.cash-register__keypad-spacer
.cash-register__keypad-actions
button.cash-register-key.cash-register-key--dep(v-on:click="addLine") Add
button.cash-register-key.cash-register-key--sub(v-on:click='addSub') Sub
button.cash-register-key.cash-register-key--tend(v-on:click='tend') Tend
.cash-register__drawer(v-bind:class="{'cash-register__drawer--open': tending}")
.cash-register__float
- for(let n = 0; n < 20; n++)
.cash-register__note.cash-register__note--float 💵
.cash-register__cash
.cash-register__note-wrap(v-for="n in notes", v-bind:style="{'--x': n[0]}")
.cash-register__note(v-bind:style="{'--y':n[1], '--rotation': n[2]}") 💵
.cash-register__drawer-front(v-on:click='tend')
*
*:before
*:after
box-sizing border-box
$color = #bfbfbf
body
align-items center
background-color #36d7b7
font-family 'Arial', sans-serif
display flex
justify-content center
min-height 100vh
overflow-x hidden
.cash-register
&__total-wrap
display flex
justify-content flex-end
&__total
border 10px solid lighten($color, 45%)
background black
display grid
grid-template-columns repeat(2, 2fr) repeat(2, 3fr) 1fr repeat(2, 2fr)
grid-gap 0
height 50px
width 50%
&__loop-track
transform translateY(calc(var(--trans) * -100%))
transition transform .15s
&__loop
$font-size = 30px
background #111
color #fafafa
height $font-size
line-height $font-size
overflow hidden
text-align center
div
sup
height 100%
display block
font-size 22px
text-align center
sup
top 0
font-size .75rem
line-height 1.25rem
$keyHeight = 24px
$keyWidth = 30px
$keypadPadding = 10px
&-key
$keyColor = #eee
background $keyColor
border 1px solid darken($keyColor, 25%)
box-shadow 0 5px 0 darken($keyColor, 60%)
cursor pointer
font-size 6px
font-weight bold
height $keyHeight
padding 0
text-transform uppercase
transform translateY(0)
width $keyWidth
outline 0
&:active
transform translateY(5px)
box-shadow 0 0 0 transparent
apply-color(c)
background c
border 1px solid darken(c, 25%)
box-shadow 0 5px 0 darken(c, 60%)
&--top:active
transform translateY(15px)
&--big-dollar
apply-color(rgb(254, 194, 135))
&--dep
apply-color(rgb(96, 178, 78))
&--sub
apply-color(rgb(247, 189, 201))
&--tend
apply-color(rgb(92, 195, 228))
grid-column 1 / -1
width 100%
&__keypad
clip-path inset(($keyHeight / 2) 0 0 0)
-webkit-clip-path inset(($keyHeight / 2) 0 0 0)
display grid
grid-template-columns repeat(4, $keyWidth) auto
grid-template-rows repeat(3, 1fr)
padding 0 $keypadPadding $keypadPadding
position relative
transform translateY(-($keyHeight))
&-wrap
background lighten($color, 25%)
&-actions
display grid
grid-column 5
grid-row 2 / -1
grid-template-columns repeat(2, 1fr)
grid-template-rows repeat(2, 1fr)
padding-left $keypadPadding
&-spacer
grid-column 5
grid-row 1
&__mid
height 40px
background lighten($color, 5%)
position relative
&__key
height 20px
width 20px
background lighten($color, 35%)
border 2px solid lighten($color, 60%)
border-radius 100%
position absolute
right 20px
top 50%
transform translate(0, -50%)
&:after
content ''
height 2px
width 10px
position absolute
top 50%
left 50%
background darken($color, 75%)
transform translate(-50%, -50%) rotate(-35deg)
&__receipt-feed
background darken($color, 75%)
content ''
height 10px
left 10px
position absolute
top 5px
width 70px
&__receipt
background white
top 100%
left 0
position absolute
transition transform .25s .5s
transform translateY(calc(var(--trans) * -16px))
width 100%
padding 0
margin 0
$receiptItemSize = 16px
&__receipt-container
bottom 5px
position absolute
left 10px
width 50px
height (3.5 * $receiptItemSize)
overflow hidden
&__receipt-item
$itemColor = #dadfe1
height $receiptItemSize
width 100%
position relative
&:before
content ''
position absolute
height 8px
width 50%
top 50%
left 5px
background $itemColor
transform translateY(-50%)
&:after
content ''
position absolute
height 8px
width 20%
right 5px
top 50%
background $itemColor
transform translateY(-50%)
&__cash
align-items center
display grid
grid-template-columns repeat(10,15px)
grid-template-rows 1fr
height 100%
justify-content center
left 50%
line-height 50px
position absolute
top 0
transform translate(-50%, -25%)
width 100%
&__float
border 10px solid transparent
border-bottom 0
border-top 0
display grid
height 100%
position absolute
grid-template-columns repeat(20,15px)
grid-template-rows 1fr
overflow-x hidden
top 0
transform translateY(-25%)
width 100%
$noteDuration = 1s
$noteDelay = .2s
&__note
animation-delay $noteDelay
animation-duration $noteDuration
animation-fill-mode backwards
animation-timing-function cubic-bezier(0,.64,.25,1.01)
font-size 2.5rem
opacity 0
transform-origin center
transform translateY(calc(var(--y) * -1px)) rotate(calc(var(--rotation) * 1deg))
overflow hidden
&--float
opacity 1
transform rotate(90deg)
&-wrap
animation-delay $noteDelay
animation-duration $noteDuration
animation-fill-mode backwards
animation-timing-function cubic-bezier(0,.64,.25,1.01)
transform translateX(calc(var(--x) * 5px))
&__drawer
background black
height 50px
position relative
transform translateY(-16px)
&:before
border 5px solid darken($color, 50%)
content ''
height 100%
left 0
position absolute
top 0
width 100%
&--open
.cash-register__drawer-front
animation open .1s
animation-fill-mode forwards
.cash-register__note
animation-name fly
.cash-register__note-wrap
animation-name fly-x
&-front
background darken($color, 25%)
cursor pointer
cursor -webkit-grab
height 100%
width 100%
transform translate(0, 0)
// handle
&:before
background lighten($color, 50%)
border-radius 0
content ''
height 5px
left 50%
position absolute
top 50%
transform translate(-50%, -50%)
width 40px
// outline
&:after
border 4px solid darken($color, 50%)
bottom 5px
content ''
left 5px
position absolute
right 5px
top 5px
@keyframes fly
0%
opacity 1
transform translateY(0) rotate(90deg)
50%
opacity 1
@keyframes fly-x
from
transform translateX(0)
@keyframes open
95%
transform translate(0, 30%)
100%
transform translate(0, 25%)
const getRandom = () => Math.floor(Math.random() * 10)
const createNoteLocations = () => {
const loc = []
for (let i = 0; i < 10; i++) {
loc.push([
Math.floor(Math.random() * 100) - 50,
Math.floor(Math.random() * 300) + 150,
Math.floor(Math.random() * 90) - 90
])
}
return loc
}
const app = new Vue({
el: '.cash-register',
data: {
subbing: false,
lines: 0,
receiptLines: 0,
showLines: 0,
amount: [0, 0, 0, 0],
temp: [0, 0, 0, 0],
notes: createNoteLocations(),
tending: false,
registerNoise: new Audio('https://freesound.org/data/previews/184/184438_850742-lq.mp3')
},
methods: {
addToLine: function(e) {
this.temp[e.target.getAttribute('data-amount-index')] = getRandom()
},
addReceiptItem: function(lines = 1) {
this.amount = this.temp
this.temp = [0, 0, 0, 0]
this.lines = this.lines + 1
this.receiptLines = this.receiptLines + lines
this.$nextTick(() => {
this.showLines = this.showLines + lines
})
},
addLine: function() {
this.addReceiptItem()
},
addSub: function() {
this.addReceiptItem(2)
},
tend: function(e) {
if ((this.tending === false && e.target.className.indexOf('front') !== -1) || (this.tending && e.target.className.indexOf('tend') !== -1)) return
this.tending = !this.tending
if (this.tending) {
this.registerNoise.play()
}
if (this.tending === false)
this.registerNoise.pause()
this.registerNoise.currentTime = 0
this.notes = createNoteLocations()
}
},
})
Also see: Tab Triggers