Created
July 11, 2023 19:57
-
-
Save wysRocket/878857853e31ce92fb83eed39fb142a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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>`; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "dependencies": { | |
| "lit": "^2.7.4", | |
| "@lit-labs/motion": "^1.0.3" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } | |
| `, | |
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "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