Skip to content

Instantly share code, notes, and snippets.

View lonekorean's full-sized avatar

Will Boyd lonekorean

View GitHub Profile
@lonekorean
lonekorean / file.js
Last active October 14, 2018 13:36
Custom properties for polka dots
CSS.registerProperty({
name: '--dot-spacing',
syntax: '<length>',
initialValue: '20px',
inherits: false
});
CSS.registerProperty({
name: '--dot-fade-offset',
syntax: '<percentage>',
initialValue: '0%',
@lonekorean
lonekorean / file.css
Last active March 7, 2018 21:22
Using a paint worklet as a mask
.jagged {
--tooth-width: 80px;
--tooth-height: 30px;
-webkit-mask-image: paint(jagged-edge);
/* other styles as needed... */
}
.slot:nth-child(1) .jagged {
background-image: linear-gradient(to right, #22c1c3, #fdbb2d);
@lonekorean
lonekorean / file.css
Created March 3, 2018 14:14
Setting custom properties for a paint worklet to use
.jagged {
background: paint(jagged-edge);
/* other styles as needed... */
}
.slot:nth-child(1) .jagged {
--tooth-width: 50px;
--tooth-height: 25px;
}
@lonekorean
lonekorean / file.js
Last active April 21, 2023 07:40
Registering custom properties
CSS.registerProperty({
name: '--tooth-width',
syntax: '<length>',
initialValue: '40px',
inherits: false
});
CSS.registerProperty({
name: '--tooth-height',
syntax: '<length>',
initialValue: '20px',
@lonekorean
lonekorean / file.js
Created March 3, 2018 14:05
Paint worklet to create jagged edge
class JaggedEdgePainter {
static get inputProperties() {
return ['--tooth-width', '--tooth-height'];
}
paint(ctx, size, props) {
let toothWidth = props.get('--tooth-width').value;
let toothHeight = props.get('--tooth-height').value;
// lots of math to ensure teeth are collectively centered
@lonekorean
lonekorean / file.css
Last active March 3, 2018 14:01
CSS properties that border is shorthand for
.shorthand {
border: 1px solid blue;
}
.expanded {
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-style: solid;
@lonekorean
lonekorean / file.js
Last active March 3, 2018 13:58
Paint worklet for placeholder box that uses input properties
class PlaceholderBoxPropsPainter {
static get inputProperties() {
return ['border-top-width', 'border-top-color'];
}
paint(ctx, size, props) {
// default values
ctx.lineWidth = 2;
ctx.strokeStyle = '#666';
@lonekorean
lonekorean / file.css
Created March 2, 2018 21:33
CSS for placeholder box demo
.placeholder {
background-image: paint(placeholder-box);
/* other styles as needed... */
}
@lonekorean
lonekorean / file.html
Created March 2, 2018 21:29
Markup for placeholder box demo
<script>
CSS.paintWorklet.addModule('worklet.js');
</script>
<div class="placeholder"></div>
@lonekorean
lonekorean / file.js
Created March 2, 2018 21:26
Placeholder box paint worklet
class PlaceholderBoxPainter {
paint(ctx, size) {
ctx.lineWidth = 2;
ctx.strokeStyle = '#666';
// draw line from top left to bottom right
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(size.width, size.height);
ctx.stroke();