Skip to content

Write HTML. Render video. Built for agents.

11.5 KB
Raw Blame
{"html":"<!doctype html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"UTF-8\" />\n    <meta name=\"viewport\" content=\"width=1920, height=1080\" />\n    <title>Parallax Layers</title>\n    <link rel=\"preconnect\" href=\"https://fonts.googleapis.com\" />\n    <link rel=\"preconnect\" href=\"https://fonts.gstatic.com\" crossorigin />\n    <link\n      href=\"https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&display=swap\"\n      rel=\"stylesheet\"\n    />\n    <script src=\"https://cdn.jsdelivr.net/npm/[email protected]/dist/gsap.min.js\"></script>\n    <style>\n      *,\n      *::before,\n      *::after {\n        box-sizing: border-box;\n      }\n\n      html,\n      body {\n        width: 1920px;\n        height: 1080px;\n        margin: 0;\n        overflow: hidden;\n        background: #000;\n        font-family: \"Instrument Serif\", serif;\n      }\n\n      #parallax-layers {\n        position: relative;\n        width: 1920px;\n        height: 1080px;\n        overflow: hidden;\n        background: #000;\n      }\n\n      /* Behind captions: big red 3D text */\n      .behind-caption-layer {\n        position: absolute;\n        inset: 0;\n        z-index: 10;\n        pointer-events: none;\n        transform: translateZ(0);\n      }\n\n      /* Front captions */\n      .front-caption-layer {\n        position: absolute;\n        inset: 0;\n        z-index: 30;\n        pointer-events: none;\n        transform: translateZ(0);\n      }\n\n      .behind-safe-zone {\n        position: absolute;\n        top: 40px;\n        left: 0;\n        width: 1920px;\n        height: 500px;\n      }\n\n      .front-safe-zone {\n        position: absolute;\n        top: 700px;\n        left: 0;\n        width: 1920px;\n        height: 300px;\n      }\n\n      .caption-block {\n        position: absolute;\n        left: 50%;\n        top: 0;\n        transform: translateX(-50%);\n        opacity: 0;\n        transform-origin: 50% 50%;\n        will-change: transform, opacity;\n        backface-visibility: hidden;\n      }\n\n      .caption-line {\n        display: flex;\n        align-items: baseline;\n        justify-content: center;\n        gap: 14px;\n        line-height: 1.1;\n        white-space: nowrap;\n      }\n\n      .caption-line--behind {\n        transform: scaleY(2.8);\n        transform-origin: 50% 0%;\n      }\n\n      .word {\n        display: inline-block;\n        will-change: transform, opacity;\n        backface-visibility: hidden;\n      }\n\n      .word--behind {\n        font-family: \"Instrument Serif\", serif;\n        font-size: 220px;\n        font-weight: 400;\n        font-style: normal;\n        line-height: 0.9;\n        color: #e50914;\n        -webkit-text-stroke: 5px #e50914;\n        text-shadow: 2px 4px 4px #a30610;\n      }\n\n      .word--front-normal {\n        font-family: \"Instrument Serif\", serif;\n        font-size: 130px;\n        font-weight: 400;\n        font-style: normal;\n        color: #eeeeee;\n        text-shadow:\n          0 2px 12px rgba(0, 0, 0, 0.6),\n          0 4px 24px rgba(0, 0, 0, 0.35);\n      }\n\n      .word--front-italic {\n        font-family: \"Instrument Serif\", serif;\n        font-size: 130px;\n        font-weight: 400;\n        font-style: italic;\n        color: #eeeeee;\n        text-shadow:\n          0 2px 12px rgba(0, 0, 0, 0.6),\n          0 4px 24px rgba(0, 0, 0, 0.35);\n      }\n    </style>\n  </head>\n  <body>\n    <div\n      id=\"parallax-layers\"\n      data-composition-id=\"caption-parallax-layers\"\n      data-start=\"0\"\n      data-duration=\"8\"\n      data-fps=\"30\"\n      data-width=\"1920\"\n      data-height=\"1080\"\n    >\n      <div class=\"behind-caption-layer\" aria-hidden=\"true\">\n        <div id=\"behind-stage\" class=\"behind-safe-zone\"></div>\n      </div>\n\n      <div class=\"front-caption-layer\" aria-hidden=\"true\">\n        <div id=\"front-stage\" class=\"front-safe-zone\"></div>\n      </div>\n    </div>\n\n    <script>\n      var DURATION = 8;\n      var BEHIND_WIDTH = 1800;\n      var FRONT_WIDTH = 1750;\n      var ENTRY_DUR = 0.1;\n      var SLIDE_DUR = 0.2;\n\n      var _fitCanvas = document.createElement(\"canvas\");\n      var _fitCtx = _fitCanvas.getContext(\"2d\");\n      function fitFontSize(text, baseFontSize, fontWeight, fontFamily, maxWidth) {\n        var size = baseFontSize;\n        var minSize = Math.floor(baseFontSize * 0.45);\n        while (size > minSize) {\n          _fitCtx.font = fontWeight + \" \" + size + \"px \" + fontFamily;\n          if (_fitCtx.measureText(text).width <= maxWidth) return size;\n          size -= 2;\n        }\n        return minSize;\n      }\n\n      var W = [\n        { text: \"Every\", start: 0.0, end: 0.3 },\n        { text: \"great\", start: 0.3, end: 0.55 },\n        { text: \"video\", start: 0.55, end: 0.85 },\n        { text: \"starts\", start: 0.85, end: 1.1 },\n        { text: \"with\", start: 1.1, end: 1.25 },\n        { text: \"a\", start: 1.25, end: 1.35 },\n        { text: \"single\", start: 1.35, end: 1.65 },\n        { text: \"frame.\", start: 1.65, end: 2.0 },\n        { text: \"HyperFrames\", start: 2.1, end: 2.65 },\n        { text: \"lets\", start: 2.65, end: 2.85 },\n        { text: \"you\", start: 2.85, end: 2.95 },\n        { text: \"write\", start: 2.95, end: 3.15 },\n        { text: \"HTML\", start: 3.15, end: 3.55 },\n        { text: \"and\", start: 3.55, end: 3.65 },\n        { text: \"render\", start: 3.65, end: 3.95 },\n        { text: \"professional\", start: 3.95, end: 4.45 },\n        { text: \"video.\", start: 4.45, end: 4.8 },\n        { text: \"No\", start: 4.9, end: 5.05 },\n        { text: \"timeline.\", start: 5.05, end: 5.45 },\n        { text: \"No\", start: 5.5, end: 5.65 },\n        { text: \"drag\", start: 5.65, end: 5.85 },\n        { text: \"and\", start: 5.85, end: 5.95 },\n        { text: \"drop.\", start: 5.95, end: 6.25 },\n        { text: \"Just\", start: 6.35, end: 6.55 },\n        { text: \"code\", start: 6.55, end: 6.8 },\n        { text: \"that\", start: 6.8, end: 6.95 },\n        { text: \"becomes\", start: 6.95, end: 7.3 },\n        { text: \"cinema.\", start: 7.3, end: 7.7 },\n      ];\n\n      // behind=red 3D emphasis words, front=normal white words\n      var BLOCKS = [\n        { behind: null, front: [[0], [1], [2]] },\n        { behind: [[3]], front: [[4], [5]] },\n        { behind: [[6]], front: [[7]] },\n        { behind: [[8]], front: [[9], [10], [11]] },\n        { behind: [[12]], front: [[13], [14]] },\n        { behind: [[15]], front: [[16]] },\n        { behind: null, front: [[17], [18]] },\n        { behind: null, front: [[19], [20], [21], [22]] },\n        { behind: [[24]], front: [[23], [25], [26]] },\n        { behind: [[27]], front: null },\n      ];\n\n      var behindStage = document.getElementById(\"behind-stage\");\n      var frontStage = document.getElementById(\"front-stage\");\n\n      BLOCKS.forEach(function (block, bi) {\n        var bEl = document.createElement(\"div\");\n        bEl.className = \"caption-block\";\n        bEl.id = \"bb\" + bi;\n        if (block.behind) {\n          var behindText = block.behind\n            .map(function (wi_arr) {\n              return W[wi_arr[0]].text;\n            })\n            .join(\" \");\n          var behindSize = fitFontSize(behindText, 220, \"400\", \"Instrument Serif\", BEHIND_WIDTH);\n          var bLine = document.createElement(\"div\");\n          bLine.className = \"caption-line caption-line--behind\";\n          block.behind.forEach(function (wi_arr, wi) {\n            var span = document.createElement(\"span\");\n            span.className = \"word word--behind\";\n            span.id = \"bb\" + bi + \"w\" + wi;\n            span.textContent = W[wi_arr[0]].text;\n            span.style.fontSize = behindSize + \"px\";\n            bLine.appendChild(span);\n          });\n          bEl.appendChild(bLine);\n        }\n        behindStage.appendChild(bEl);\n\n        var fEl = document.createElement(\"div\");\n        fEl.className = \"caption-block\";\n        fEl.id = \"fb\" + bi;\n        if (block.front) {\n          var frontText = block.front\n            .map(function (wi_arr) {\n              return W[wi_arr[0]].text;\n            })\n            .join(\" \");\n          var frontSize = fitFontSize(frontText, 130, \"400\", \"Instrument Serif\", FRONT_WIDTH);\n          var fLine = document.createElement(\"div\");\n          fLine.className = \"caption-line\";\n          block.front.forEach(function (wi_arr, wi) {\n            var span = document.createElement(\"span\");\n            var isItalic = wi_arr[0] === 7 || wi_arr[0] === 18; // frame., timeline.\n            span.className = \"word \" + (isItalic ? \"word--front-italic\" : \"word--front-normal\");\n            span.id = \"fb\" + bi + \"w\" + wi;\n            span.textContent = W[wi_arr[0]].text;\n            span.style.fontSize = frontSize + \"px\";\n            fLine.appendChild(span);\n          });\n          fEl.appendChild(fLine);\n        }\n        frontStage.appendChild(fEl);\n      });\n\n      var allBehind = BLOCKS.map(function (_, i) {\n        return document.getElementById(\"bb\" + i);\n      });\n      var allFront = BLOCKS.map(function (_, i) {\n        return document.getElementById(\"fb\" + i);\n      });\n\n      function applyBehindScales() {\n        BLOCKS.forEach(function (block, bi) {\n          if (block.behind) {\n            var line = allBehind[bi].querySelector(\".caption-line\");\n            if (line) {\n              var natW = line.scrollWidth;\n              if (natW > 0) {\n                var s = BEHIND_WIDTH / natW;\n                line.style.transform = \"scaleX(\" + s + \") scaleY(2.8)\";\n              }\n            }\n          }\n        });\n      }\n      applyBehindScales();\n\n      window.__timelines = window.__timelines || {};\n      var tl = gsap.timeline({ paused: true });\n\n      function blockStart(bi) {\n        var b = BLOCKS[bi];\n        var firstIdx = b.behind ? b.behind[0][0] : b.front[0][0];\n        return W[firstIdx].start;\n      }\n\n      BLOCKS.forEach(function (block, bi) {\n        var start = blockStart(bi);\n        var nextStart = bi < BLOCKS.length - 1 ? blockStart(bi + 1) : DURATION;\n        var bEl = allBehind[bi];\n        var fEl = allFront[bi];\n\n        allBehind.forEach(function (other, oi) {\n          if (oi !== bi) tl.set(other, { opacity: 0 }, start);\n        });\n        allFront.forEach(function (other, oi) {\n          if (oi !== bi) tl.set(other, { opacity: 0 }, start);\n        });\n\n        if (block.behind) {\n          tl.set(bEl, { opacity: 1 }, start);\n          block.behind.forEach(function (wi_arr, wi) {\n            var wordEl = document.getElementById(\"bb\" + bi + \"w\" + wi);\n            var wordStart = W[wi_arr[0]].start;\n            tl.set(wordEl, { opacity: 0 }, start);\n            tl.to(wordEl, { opacity: 1, duration: ENTRY_DUR, ease: \"power2.out\" }, wordStart);\n          });\n        }\n\n        if (block.front) {\n          tl.set(fEl, { opacity: 1 }, start);\n          block.front.forEach(function (wi_arr, wi) {\n            var wordEl = document.getElementById(\"fb\" + bi + \"w\" + wi);\n            var wordStart = W[wi_arr[0]].start;\n            tl.set(wordEl, { opacity: 0 }, start);\n            tl.set(wordEl, { opacity: 1 }, wordStart);\n          });\n        }\n\n        tl.set(bEl, { opacity: 0 }, nextStart);\n        tl.set(fEl, { opacity: 0 }, nextStart);\n      });\n\n      tl.to({}, { duration: DURATION }, 0);\n      window.__timelines[\"caption-parallax-layers\"] = tl;\n\n      document.fonts.ready.then(function () {\n        applyBehindScales();\n      });\n    </script>\n  </body>\n</html>\n"}