Skip to content

Instantly share code, notes, and snippets.

@wysRocket
Created July 11, 2023 19:57
Show Gist options
  • Select an option

  • Save wysRocket/878857853e31ce92fb83eed39fb142a5 to your computer and use it in GitHub Desktop.

Select an option

Save wysRocket/878857853e31ce92fb83eed39fb142a5 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<head>
<script type="module" src="./motion-grid.js"></script>
<style>
body {
margin: 0;
height: 100vh;
width: 100vw;
font-family: sans-serif;
}
</style>
</head>
<body>
<motion-grid></motion-grid>
</body>
import {LitElement, html} from 'lit';
import {customElement, state} from 'lit/decorators.js';
import {animate} from '@lit-labs/motion';
import {styles} from './styles.js';
@customElement('motion-grid')
export class MotionGrid extends LitElement {
static styles = styles;
@state() layout = 0;
render() {
const d = 1000;
const a = Array(5).fill(null, 0);
return html` <section
@click=${() => (this.layout = (this.layout + 1) % (a.length - 1))}
class="container layout${this.layout}"
>
${a.map(
(v, i) => html`<div
class="item${i}"
${animate({
keyframeOptions: {
delay: (i * d) / (a.length * 2),
duration: d,
fill: 'both',
},
})}
></div>`
)}
</section>
<span class="message">click</span>`;
}
}
{
"dependencies": {
"lit": "^2.7.4",
"@lit-labs/motion": "^1.0.3"
}
}
import {css} from 'lit';
export const styles = [
css`
.container {
display: grid;
height: 100vh;
width: 100vw;
}
.container.layout0 {
grid-template-areas:
'a a a a a a'
'b c c c c d'
'b c c c c d'
'b c c c c d'
'b c c c c d'
'b c c c c d'
'e e e e e e';
}
.container.layout2 {
grid-template-areas:
'b a a a a d'
'b c c c c d'
'b c c c c d'
'b c c c c d'
'b c c c c d'
'b c c c c d'
'b e e e e d';
}
.container.layout1 {
grid-template-areas:
'a a c c c c'
'a a c c c c'
'a a d d d d'
'b b d d d d'
'b b e e e e'
'b b e e e e';
}
.container.layout3 {
grid-template-areas:
'a a a a c c'
'a a a a c c'
'a a a a d d'
'b b b b d d'
'b b b b e e'
'b b b b e e';
}
.item0 {
grid-area: a;
background: #002171;
}
.item1 {
grid-area: b;
background: #5472d3;
}
.item2 {
grid-area: c;
background: #e1e2e1;
}
.item3 {
grid-area: d;
background: #7f0000;
}
.item4 {
grid-area: e;
background: #560027;
}
.message {
position: absolute;
top: 1em;
left: 1em;
color: #aaa;
font-style: italic;
font-weight: bold;
font-size: 2em;
}
`,
];
{
"files": {
"motion-grid.ts": {
"position": 0
},
"styles.ts": {
"position": 1
},
"index.html": {
"position": 2
},
"package.json": {
"position": 3,
"hidden": true
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment