返回 html-video
captions.html
1 <template id="captions-template">
2 <div
3 data-composition-id="captions"
4 data-width="1920"
5 data-height="1080"
6 data-duration="__VIDEO_DURATION__"
7 >
8 <div id="caption-container"></div>
9
10 <style>
11 [data-composition-id="captions"] {
12 width: 1920px;
13 height: 1080px;
14 position: relative;
15 font-family: "Helvetica", "Arial", sans-serif;
16 font-weight: bold;
17 overflow: hidden;
18 }
19
20 [data-composition-id="captions"] #caption-container {
21 position: absolute;
22 bottom: 120px; /* Consistent bottom positioning */
23 left: 50%;
24 transform: translateX(-50%);
25 display: flex;
26 justify-content: center;
27 align-items: center;
28 width: 100%;
29 }
30
31 [data-composition-id="captions"] .caption-box {
32 background-color: #0a1e3d; /* Solid navy */
33 padding: 20px 40px;
34 display: none; /* Hidden by default, shown via GSAP */
35 justify-content: center;
36 align-items: center;
37 /* Swiss Grid: sharp corners, solid block */
38 }
39
40 [data-composition-id="captions"] .caption-text {
41 color: #f2f2f2; /* Off-white */
42 font-size: 72px;
43 text-transform: uppercase; /* Swiss style often uses uppercase for impact */
44 letter-spacing: -2px;
45 line-height: 1;
46 white-space: nowrap;
47 text-align: center;
48 max-width: 1600px;
49 overflow: hidden;
50 }
51 </style>
52
53 <script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
54 <script>
55 (function () {
56 const TRANSCRIPT = [
57 { text: "We", start: 0.119, end: 0.259 },
58 { text: "asked", start: 0.319, end: 0.479 },
59 { text: "what", start: 0.519, end: 0.659 },
60 { text: "you", start: 0.699, end: 0.819 },
61 { text: "needed.", start: 0.859, end: 1.819 },
62 { text: "Forty-seven", start: 1.86, end: 2.299 },
63 { text: "percent", start: 2.399, end: 2.679 },
64 { text: "of", start: 2.7, end: 2.799 },
65 { text: "you", start: 2.839, end: 2.939 },
66 { text: "said", start: 3.039, end: 3.179 },
67 { text: "motion", start: 3.24, end: 3.559 },
68 { text: "graphics,", start: 3.579, end: 4.599 },
69 { text: "sixty-two", start: 4.679, end: 5.179 },
70 { text: "percent", start: 5.299, end: 5.759 },
71 { text: "said", start: 5.859, end: 5.98 },
72 { text: "static", start: 6.079, end: 6.399 },
73 { text: "content", start: 6.46, end: 6.879 },
74 { text: "was", start: 6.92, end: 7.079 },
75 { text: "costing", start: 7.099, end: 7.48 },
76 { text: "you", start: 7.5, end: 7.579 },
77 { text: "attention,", start: 7.679, end: 8.659 },
78 { text: "and", start: 8.699, end: 8.86 },
79 { text: "three", start: 8.88, end: 9.06 },
80 { text: "out", start: 9.079, end: 9.18 },
81 { text: "of", start: 9.199, end: 9.34 },
82 { text: "four", start: 9.38, end: 9.799 },
83 { text: "said", start: 9.84, end: 10.0 },
84 { text: "you", start: 10.019, end: 10.159 },
85 { text: "know", start: 10.179, end: 10.36 },
86 { text: "the", start: 10.38, end: 10.42 },
87 { text: "look", start: 10.519, end: 10.699 },
88 { text: "you", start: 10.739, end: 10.859 },
89 { text: "want", start: 10.98, end: 11.34 },
90 { text: "but", start: 11.359, end: 11.52 },
91 { text: "don't", start: 11.56, end: 11.779 },
92 { text: "have", start: 11.819, end: 11.94 },
93 { text: "the", start: 11.96, end: 12.06 },
94 { text: "editing", start: 12.079, end: 12.4 },
95 { text: "skills", start: 12.52, end: 12.86 },
96 { text: "to", start: 12.88, end: 13.0 },
97 { text: "get", start: 13.019, end: 13.18 },
98 { text: "there.", start: 13.22, end: 14.22 },
99 { text: "So", start: 14.239, end: 14.399 },
100 { text: "we", start: 14.42, end: 14.52 },
101 { text: "built", start: 14.619, end: 14.88 },
102 { text: "Hyperframes", start: 15.079, end: 15.42 },
103 ];
104 const container = document.getElementById("caption-container");
105 const tl = gsap.timeline({ paused: true });
106
107 if (!TRANSCRIPT || TRANSCRIPT.length === 0) {
108 window.__timelines = window.__timelines || {};
109 window.__timelines["captions"] = tl;
110 return;
111 }
112
113 // Group transcript into max 5 words per group
114 const groups = [];
115 let currentGroup = [];
116
117 TRANSCRIPT.forEach((word, index) => {
118 currentGroup.push(word);
119 // Group by 5 words OR if it's the last word
120 if (currentGroup.length === 5 || index === TRANSCRIPT.length - 1) {
121 groups.push([...currentGroup]);
122 currentGroup = [];
123 }
124 });
125
126 // Create DOM elements and timeline for each group
127 groups.forEach((group, i) => {
128 const box = document.createElement("div");
129 box.className = "caption-box";
130 box.id = `group-${i}`;
131
132 const text = document.createElement("div");
133 text.className = "caption-text";
134 text.textContent = group.map((w) => w.text).join(" ");
135
136 box.appendChild(text);
137 container.appendChild(box);
138
139 const startTime = group[0].start;
140 const endTime = group[group.length - 1].end;
141
142 // Hard cut animation (no fades) as requested
143 tl.set(box, { display: "flex" }, startTime);
144 tl.set(box, { display: "none" }, endTime);
145 });
146
147 window.__timelines["captions"] = tl;
148 })();
149 </script>
150 </div>
151 </template>
152
152 lines HTML