<!--
Worklet code here. I can't put this under JS pane anymore since
I can't do CSS.paintWorklet.addModule('/rrenula/pen/js-code.js'); due to
cors issue
-->
<script language="worklet">
if (typeof registerPaint !== 'undefined') {
class Checkbox {
paint(ctx, size, props) {
const x = 0
const y = 0
const finalX = size.width
const finalY = size.height
ctx.beginPath()
ctx.moveTo(x, y)
ctx.lineTo(finalX, finalY)
ctx.stroke()
ctx.beginPath();
ctx.moveTo(finalX, y);
ctx.lineTo(x, finalY);
ctx.stroke();
}
}
registerPaint('checkbox', Checkbox)
}
</script>
<script type="module">
function ready(fn) {
if (document.readyState != 'loading'){
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
ready(() => {
function blobWorklet() {
const qs = document.querySelector('script[language="worklet"]')
const src = qs.innerHTML;
const blob = new Blob([src], {type: 'text/javascript'});
return URL.createObjectURL(blob);
}
CSS.paintWorklet.addModule(blobWorklet())
if ('paintWorklet' in CSS) {
document.querySelector('.notice').classList.add('hidden')
}
})
</script>
<div class="wrapper">
<div class="notice">
This demo uses CSS Houdini. If you are seeing this, you need to enable CSS Houdini by navigating to <code>chrome://flags</code> and enable <code>Experimental Web Platform features</code>
</div>
<p class="q">Who would you take out on a date?</p>
<div class="checkbox-wrapper">
<input type="checkbox" class="checkbox">
<label> <span class="checkbox-label">Lord Voldemort</span></label>
</div>
<div class="checkbox-wrapper">
<input type="checkbox" class="checkbox">
<label> <span class="checkbox-label">Harry Potter</span></label>
</div>
<div class="checkbox-wrapper">
<input type="checkbox" class="checkbox">
<label> <span class="checkbox-label">Margaery Tyrell</span></label>
</div>
<div class="checkbox-wrapper">
<input type="checkbox" class="checkbox">
<label> <span class="checkbox-label">Robb Stark</span></label>
</div>
<div class="checkbox-wrapper">
<input type="checkbox" class="checkbox">
<label> <span class="checkbox-label">Legolas</span></label>
</div>
<div class="checkbox-wrapper">
<input type="checkbox" class="checkbox">
<label> <span class="checkbox-label">Yennefer</span></label>
</div>
<div class="checkbox-wrapper">
<input type="checkbox" class="checkbox">
<label> <span class="checkbox-label">Geralt</span></label>
</div>
</div>
/* CSS files add styling rules to your content */
body {
font-family: "Benton Sans", "Helvetica Neue", helvetica, arial, sans-serif;
margin: 2em;
background: #9e4fdb;
color: #fff;
font-family: 'Lato', sans-serif;
}
h1 {
font-style: italic;
color: #373fff;
}
.q {
font-size: 2.5rem;
font-weight: 300;
}
.wrapper {
max-width: 960px;
margin: 20px auto;
}
.checkbox-label {
font-size: 2rem;
vertical-align: middle;
color: #68388e;
}
.checkbox-wrapper {
margin-bottom: 16px;
}
.checkbox {
--edge: 10;
transition: --checkbox-color 500ms, background-color 500ms;
}
@supports (background: paint(id)) {
.checkbox {
appearance: none;
background-image: paint(checkbox);
}
}
.checkbox:hover {
--checkbox-color: #ccc;
}
.checkbox:checked {
--checkbox-color: white;
background-color: deeppink;
}
.checkbox:checked + label > .checkbox-label {
color: #fff;
}
.checkbox {
--checkbox-color: transparent;
margin-right: 24px;
vertical-align: middle;
width: 50px;
height: 50px;
border-radius: 2px;
border: 3px solid #fff;
transition: --checkbox-color 500ms, background-color 500ms;
}
.notice {
background-color: darkred;
padding: 8px;
font-size: 20px;
line-height: 1.5;
}
.hidden {
display: none;
}
// The JS code for this pen is at the top of the HTML
This Pen doesn't use any external JavaScript resources.