emoji
Emoji or small pictures that float up from a like button, burst out of a success state or rain over a section.
Live preview needs WebGPU or WebGL 2. A live stream with a like button that sends hearts floating up over the picture on every tap.
This example failed to draw.
Usage
Put it on any element: a like or reaction button, a form, a section. start() registers emoji, so the attribute alone puts it on an element. The tabs below are the example above, with the values you set.
To change its code, copy the source into your effects folder; the copy replaces the built-in.
npx @dioramajs/diorama add emoji<div class="ej-stream"> <div class="ej-screen" role="img" aria-label="A live stream of a rooftop rehearsal at dusk" > <span class="ej-live">Live</span> <span class="ej-viewers">2.4K watching</span> </div> <div class="ej-bar"> <p class="ej-title">Rooftop rehearsal, set two</p> <button type="button" class="ej-like" aria-pressed="false" data-dio="emoji" data-dio-origin="pointer" > ❤️ <span class="ej-count">318</span> </button> </div></div>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.ej-like', 'emoji', { motion: 'float', trigger: 'click', origin: 'pointer', count: 8, scale: 1, speed: 1, spread: 40, sway: 12, spin: 1, duration: 2.4,})import { start } from '@dioramajs/diorama'import emoji from '@dioramajs/particles/emoji'
const app = start()app.attach('.ej-like', emoji({ motion: 'float', trigger: 'click', origin: 'pointer', count: 8, scale: 1, speed: 1, spread: 40, sway: 12, spin: 1, duration: 2.4,}))Page transitions
The emoji fade with the page as it leaves. How a flight flies.
Params
Every param is also an attribute, and both app.attach() and the handle take it by name.
| Param | Type | Default | Description |
|---|---|---|---|
triggerrebuildsdata-dio-trigger | 'click' | 'view' | 'event' | 'manual' | 'interval' | 'click' |
|
motionrebuildsdata-dio-motion | 'float' | 'burst' | 'rain' | 'fountain' | 'float' |
|
emojirebuildsdata-dio-emoji | string | '❤️' | Emoji, symbols or words separated by spaces; a run of emoji without spaces counts as one each. A URL or a file name ending in .svg, .png, .webp and the like is a picture. Up to 16 different items; each emoji picks one at random. |
eventrebuildsdata-dio-event | string | '' | Name of the DOM event on the element for the event trigger; its detail may pick one emoji of the list and a count up to count. |
firedata-dio-fire | number0 to 10 | 0 | Every increase emits once with the manual trigger. |
oncedata-dio-once | boolean | false | At most one emission per page. |
originrebuildsdata-dio-origin | 'center' | 'pointer' | 'center' | center: out of the box; pointer: from the click or the pointer. Rain ignores it. |
countdata-dio-count | number0 to 300 | 8 | Emoji per emission; 0 emits none.At most low 12, medium 24 by quality tier. |
scaledata-dio-scale | number0.25 to 5 | 1 | Size of the emoji over a base of 32 px, give or take a fifth. |
speeddata-dio-speed | number0 to 3 | 1 | Speed of the motion as a factor; 0 pops the emoji in place. |
spreaddata-dio-spread | number0 to 360° | 40 | Width of the cone for float and fountain; burst flies all round. |
swaydata-dio-sway | number0 to 80 px | 12 | Side to side sway; 0 flies straight. |
spindata-dio-spin | number0 to 4 | 1 | Rocking and spin as a factor; 0 keeps the emoji upright. |
durationdata-dio-duration | number0.4 to 8 s | 2.4 | Life of an emoji. |
intervaldata-dio-interval | number0 to 10 s | 1.5 | Time between two emissions of the interval trigger; 0 stops them. |
seedrebuildsdata-dio-seed | number1 to 100 | 1 | Seed of the randomness. |
Params marked rebuilds re-run the effect's setup when they change, so set them before the element shows.
Inputs and frames
It reads height, presence, width, x and y
. Draws only while something on it moves, then stops. Only while emoji fly; none at rest. The interval trigger pauses while the element is off screen. How a frame is decided.
Reduced motion and touch
With reduced motion it is off and the element shows as plain HTML. Off: neither the module nor the engine loads for it, and the page is unchanged.
Runs on every device. A tap emits like a click.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { emoji: { reducedMotion: 'static' } } })Cost and quality
- Download
- 4.5 KB min+gzip the first time a page uses it
- GPU
- One instanced draw for a pool of 300 emoji.
- Memory
- A glyph atlas of at most 1024 x 1024 px and the pool’s attributes, about 15 KB.
- Frames
- Idle at rest
It runs from the low tier up. Each tier changes this: The quality plugin picks the tier for each device.
| Tier | What changes |
|---|---|
low | At most 12 emoji an emission. |
medium | At most 24 emoji an emission. |
Recipes
Reactions from other viewers
A stream or a webinar gets reactions from its audience over a websocket. Put one effect on the reaction bar with the event trigger and the list of reactions, and dispatch an event for every message. Its detail names the emoji to send and how many, up to count; an emoji missing from the list sends a random one of it.
Reactions from other viewers float up from the bar.
Live preview needs WebGPU or WebGL 2. A reaction bar on a dark stream page with thumbs, hearts, laughs and surprised faces floating up from it as other viewers react.
This example failed to draw.
Other viewers react every 0.7 s. Tap a reaction to send three of it.
<div class="ej-feed"> <p class="ej-note">Reactions from other viewers float up from the bar.</p> <div class="ej-picks" data-dio="emoji" data-dio-trigger="event" data-dio-event="reaction" data-dio-emoji="👍 ❤️ 😂 😮" data-dio-count="3" data-dio-spread="60" > <button type="button" data-react="👍" aria-label="Thumbs up" >👍</button> <button type="button" data-react="❤️" aria-label="Love" >❤️</button> <button type="button" data-react="😂" aria-label="Laughing" >😂</button> <button type="button" data-react="😮" aria-label="Surprised" >😮</button> </div></div>// Stands in for the reactions channel of a stream: other viewers react now and then, and every// message becomes one event on the bar. A tap on a reaction goes the same way, three of it.export default function mount(example: HTMLElement): () => void { const feed = example.querySelector<HTMLElement>('.ej-picks') if (!feed) return () => {} const react = (emoji: string, count: number) => feed.dispatchEvent( new CustomEvent('reaction', { detail: { emoji, count } }), ) const onPick = (e: Event) => { const emoji = (e.target as Element).closest<HTMLElement>( '[data-react]', )?.dataset.react if (emoji) react(emoji, 3) } const others = ['👍', '❤️', '❤️', '😂', '😮'] const timer = window.setInterval(() => { react(others[Math.floor(Math.random() * others.length)] ?? '❤️', 1) }, 700) feed.addEventListener('click', onPick) return () => { clearInterval(timer) feed.removeEventListener('click', onPick) }}const bar = document.querySelector('.reactions') as HTMLElementconst socket = new WebSocket('wss://example.com/live/reactions')
socket.addEventListener('message', (message) => { const { emoji } = JSON.parse(message.data) as { emoji: string } bar.dispatchEvent( new CustomEvent('reaction', { detail: { emoji, count: 1 } }), )})A burst when the payment goes through
A click on Pay is too early: the payment can still fail. Use the event trigger with burst, and dispatch the event once your server confirms. Say what happened in the page too; the emoji are decoration.
<section class="checkout" data-dio="emoji" data-dio-trigger="event" data-dio-event="paid" data-dio-motion="burst" data-dio-emoji="🎉 🥳 ✨" data-dio-count="24"> <button type="submit">Pay $42</button> <p role="status"></p></section>Seasonal rain over a section
The interval trigger emits every interval seconds while the section is on screen and pauses while it is not. With rain, the emoji fall through the section over its width, and a few at a time make a steady rain.
<section class="sale" data-dio="emoji" data-dio-trigger="interval" data-dio-motion="rain" data-dio-emoji="🎃🦇🍬" data-dio-count="5" data-dio-interval="0.8" data-dio-duration="3"> <h2>Halloween sale</h2></section>A run of emoji with no spaces counts as one emoji each, so 🎃🦇🍬 is a list of three.
Your own icons
A word of the list that is a URL or a file name ending in .svg, .png, .webp and the like is drawn as a picture. Keep them small and square; a picture from another origin needs CORS headers, or it is left out with a warning in development.
<button type="button" data-dio="emoji" data-dio-motion="fountain" data-dio-emoji="/icons/coin.svg /icons/star.svg" data-dio-count="16"> Claim reward</button>Notes
The effect never cancels the click: a like still counts and a form still submits. When the site swaps the button for a “Liked” label or hides it in the same click, the emoji fly on from where the button was and then stop.
The emoji are drawn once with the system emoji font, so they look like the visitor’s own emoji on Apple, Windows and Android devices. They draw on the canvas over the page and never take a click. Up to 16 different emoji or pictures make one list.
Every emoji moves with the page as it scrolls. Frames run only while emoji fly; once their element is scrolled far away they stop at once. All of them are one instanced draw from a pool of 300, and the quality tier caps count at 12 on the low tier and 24 on the medium one.
Under reduced motion neither the module nor the engine loads for it, and the element stays as it is.
trigger, motion, emoji, event, origin and seed rebuild the effect when they change. scale, sway and spin change the emoji in the air too; counts, speeds and times apply to the next emission.