The snippet, part by part
What the editor's snippet for a web page is, piece by piece, and what you can change in it.
The whole of it
For a demo called “Your demo” with steps, recorded 1280 pixels wide and 800 tall, the editor gives you this:
<div style="position:relative; width:100%; padding-top:calc(62.5% + 78px); border-radius:12px; overflow:hidden">
<iframe src="your-demo.html" title="Your demo" loading="lazy" allow="fullscreen; autoplay"
style="position:absolute; inset:0; width:100%; height:100%; border:0"></iframe>
</div>Its parts
- The box
- As wide as the space it's in, and as tall as the demo's shape needs at that width, plus 48 pixels for the controls, and 30 pixels more for the step rail when the demo has steps. Its corners are round.
- The frame
- The file, by its name, filling the box.
loading="lazy"- The file isn't asked for until the demo is near the screen.
allow="fullscreen; autoplay"- So its full-screen button works, and it can start by itself when you've asked it to.
title- What the frame is, for someone using a screen reader.
The switches aren't in it
Play straight through and Start when it scrolls into view are kept in the file, not the snippet. Change them, export again, and the same snippet plays it the new way.
Where it stops. The frame finds the file by its name: rename one and rename the other.
The pop-up's
For the same demo, the pop-up's snippet:
<button type="button" data-demo-open="demo-your-demo">See the demo</button>
<dialog id="demo-your-demo" aria-label="Your demo"
style="width:min(92vw, calc((88vh - 118px) * 1.6)); max-width:none; max-height:none; padding:40px 0 0; border:0; background:transparent; overflow:visible">
<button type="button" data-demo-close aria-label="Close the demo"
style="position:absolute; top:0; right:0; display:grid; place-items:center; width:32px; height:32px; padding:0; border:0; border-radius:50%; background:rgba(0,0,0,.55); color:#fff; cursor:pointer">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>
</button>
<div style="position:relative; width:100%; padding-top:calc(62.5% + 78px); border-radius:12px; overflow:hidden">
<iframe data-src="your-demo.html" title="Your demo" allow="fullscreen; autoplay" autofocus
style="position:absolute; inset:0; width:100%; height:100%; border:0"></iframe>
</div>
</dialog>
<style>
#demo-your-demo::backdrop { background: rgba(0, 0, 0, .6); }
/* A short screen (a phone on its side): the close button inside the corner, the box the screen's height. On a
touch screen the box is the demo's own shape, and the demo puts its controls over its foot. */
@media (max-height: 500px) {
#demo-your-demo { width: min(calc(100vw - 16px), calc((100dvh - 94px) * 1.6)) !important; padding-top: 0 !important; }
#demo-your-demo [data-demo-close] { top: 8px !important; right: 8px !important; z-index: 1; }
}
@media (max-height: 500px) and (pointer: coarse) {
#demo-your-demo { width: min(calc(100vw - 16px), calc((100dvh - 16px) * 1.6)) !important; }
#demo-your-demo > div { padding-top: 62.5% !important; }
}
</style>
<script>
(function () {
var dialog = document.getElementById("demo-your-demo");
var opener = document.querySelector('[data-demo-open="demo-your-demo"]');
var frame = dialog.querySelector("iframe");
var ready = false;
function ask(type) {
if (frame.contentWindow) frame.contentWindow.postMessage({ protocol: "demo/1", type: type }, "*");
}
opener.addEventListener("click", function () {
if (!frame.getAttribute("src")) frame.setAttribute("src", frame.getAttribute("data-src"));
dialog.showModal();
if (ready) ask("play");
});
dialog.querySelector("[data-demo-close]").addEventListener("click", function () { dialog.close(); });
dialog.addEventListener("click", function (e) { if (e.target === dialog) dialog.close(); });
dialog.addEventListener("close", function () { ask("pause"); opener.focus(); });
window.addEventListener("message", function (e) {
if (e.source !== frame.contentWindow || !e.data || e.data.protocol !== "demo/1") return;
if (e.data.type === "ready") { ready = true; if (dialog.open) ask("play"); }
else if (e.data.type === "escape") dialog.close();
});
})();
</script>- The button
- Opens the demo. Its words are yours to change.
- The dialog
- The same box as the snippet for the page, as wide as the window allows and never taller than it, with room above for the close button. Its
idcomes from the file's name, so two pop-ups on a page don't mix. - The style
- The backdrop's shade, and a short screen's rules: there the close button goes inside the corner and the box takes the screen's height; on a touch screen, the demo's own shape, its controls over its foot.
data-src- Where the file is. The frame is given it only when someone first opens the pop-up.
- The script
- Opens it, asks the demo to play once it says it's ready, and to pause when it closes; closes it on a click outside the demo or an Escape pressed inside it; puts the keyboard back on the button (talking to your page).