HTMLify
Always-forever.html
Views: 437 | Author: amar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | <!DOCTYPE html> <html> <head><meta charset="UTF-8" /> <title>Always forever</title> <style> /* --- Basic page / card --- */ body { background: #f3ebdf; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; font-family: "ComicCustom", "Comic Sans MS", Arial, sans-serif; } @font-face { font-family: "ComicCustom"; src: url("https://htmlify.me/amar/umeassets/ComicSansMS.woff2") format("woff2"); font-display: swap;} .card { width: 480px; max-width: 95%; height: 540px; /* taller to fit lyrics */ background: #fff8ef; border-radius: 20px; padding: 25px; border: 3px dashed #c19a6b; position: relative; overflow: hidden; box-sizing: border-box; } /* TEXT ON TOP */ .text { width: 100%; text-align: center; font-size: 26px; margin-bottom: 8px; position: relative; height: 40px; } .fade-text { position: absolute; width: 100%; transition: opacity 0.6s ease; opacity: 0; pointer-events: none; } .show { opacity: 1; } /* IMAGES MIDDLE */ .images { position: relative; width: 100%; height: 240px; } .images img { position: absolute; top: 10px; width: 230px; transition: transform 0.6s ease, opacity 0.6s ease; } #girl { left: -15px; } #boy { right: -15px; } #hug { left: 50%; top: 20px; width: 290px; transform: translateX(-18%); opacity: 0; position: absolute; } /* SLIDER AT BOTTOM */ #slider { position: absolute; bottom: 120px; width: 100%; height: 40px; left: 0; } #handle { width: 90px; height: 100%; background: #f3d6b5; border-radius: 25px; cursor: grab; box-shadow: 0 0 5px #be9974 inset; position: relative; left: 0; user-select: none; } #lyricsPanel { position: absolute; width: 85%; left: 50%; transform: translateX(-50%); top: 60px; height: 90px; text-align: center; z-index: 10; overflow: hidden; background: transparent; /* Transparent, no box */ border-radius: 0; /* Remove curve */ padding: 0; display: none; box-shadow: none; /* Remove shadow */ } #lyrics p { margin: 6px 0; font-size: 17px; color: #333; line-height: 1.4; } #lyrics p.active { color: #ff6b81; /* soft romantic pink-red */ font-weight: 700; font-size: 18px; } } </style> </head> <body> <div class="card"> <!-- TOP TEXT --> <div class="text"> <div id="text1" class="fade-text show">You & Me…</div> <div id="text2" class="fade-text">Always Forever ❤️</div> </div> <!-- MIDDLE IMAGES (unchanged) --> <div class="images"> <img id="girl" src="https://htmlify.me/amar/umeassets/image%20(2).png" alt="girl"> <img id="boy" src="https://htmlify.me/amar/umeassets/image%20(1).png" alt="boy"> <img id="hug" src="https://htmlify.me/amar/umeassets/image.png" alt="hug"> </div> <!-- SLIDER --> <div id="slider"> <div id="handle"></div> </div> <!-- Lyrics panel (hidden until user slides) --> <div id="lyricsPanel"> <div id="lyrics"></div> </div> <!-- Audio (HIDDEN CONTROLS) --> <div id="audioControls" style="display:none;"> <audio id="audio" preload="metadata" crossorigin="anonymous"></audio> </div> </div> <script> /* ========================= CONFIG - paste your links here ========================= */ const CONFIG = { audioSrc: "https://htmlify.me/amar/umeassets/Always%20Forever.mp3", lrcUrl: "https://htmlify.me/amar/always.lrc", songTitle: "Always Forever ❤️", titleChangeTime: 0.5 }; /* ========================= */ const audio = document.getElementById("audio"); const lyricsPanel = document.getElementById("lyricsPanel"); const lyricsDiv = document.getElementById("lyrics"); const text1 = document.getElementById("text1"); const text2 = document.getElementById("text2"); const slider = document.getElementById("slider"); const handle = document.getElementById("handle"); const girl = document.getElementById("girl"); const boy = document.getElementById("boy"); const hug = document.getElementById("hug"); let dragging = false; let startedBySlide = false; // whether audio started by slider first interaction let lines = []; // parsed lrc lines {time, text} // New vars to prevent undo and flicker let maxReachedX = 0; // maximum handle left reached (px) -> can't go left of this let titleLockedByUser = false; // when true, audio won't change top title (prevents flicker) // set audio src from config if (CONFIG.audioSrc && CONFIG.audioSrc !== "https://example.com/song.mp3") { audio.src = CONFIG.audioSrc; } else { console.warn("No audioSrc set in CONFIG — set CONFIG.audioSrc to your hosted audio URL."); } // show the configured song title text2 text2.textContent = CONFIG.songTitle || text2.textContent; // parse LRC if provided (fetch) if (CONFIG.lrcUrl && CONFIG.lrcUrl !== "https://example.com/lyrics.lrc") { fetch(CONFIG.lrcUrl) .then(r => r.text()) .then(parseLRC) .catch(err => { console.warn("Failed to load LRC:", err); }); } else { console.warn("No lrcUrl set in CONFIG — set CONFIG.lrcUrl to your hosted LRC URL."); } /* ---------- LRC parser (supports multiple timestamps per line) ---------- */ function parseLRC(text) { const rawLines = text.replace(/\r/g,"").split("\n"); const timeTag = /\[(\d+):(\d+(\.\d+)?)\]/g; for (const raw of rawLines) { let matches; let lastIndex = 0; const times = []; while ((matches = timeTag.exec(raw)) !== null) { const min = parseInt(matches[1],10); const sec = parseFloat(matches[2]); times.push(min * 60 + sec); lastIndex = matches.index + matches[0].length; } const content = raw.slice(lastIndex).trim(); times.forEach(t => { lines.push({ time: t, text: content || "" }); }); } // sort by time lines.sort((a,b) => a.time - b.time); // render lines into lyricsDiv (but keep hidden until user slides) renderLyrics(); } /* ---------- render lyrics into panel ---------- */ function renderLyrics() { lyricsDiv.innerHTML = ""; lines.forEach((ln, i) => { const p = document.createElement("p"); p.id = "line-" + i; p.textContent = ln.text || " "; lyricsDiv.appendChild(p); }); } /* ---------- slider events (desktop + mobile) ---------- */ handle.addEventListener("mousedown", () => dragging = true); document.addEventListener("mouseup", () => dragging = false); document.addEventListener("mousemove", (e) => { if (dragging) moveHandle(e.clientX); }); handle.addEventListener("touchstart", (e) => { dragging = true; e.preventDefault(); }); document.addEventListener("touchend", () => dragging = false); document.addEventListener("touchmove", (e) => { if (dragging) moveHandle(e.touches[0].clientX); }); /* ---------- move logic (prevents moving left of maxReachedX) ---------- */ function moveHandle(posX) { const rect = slider.getBoundingClientRect(); let x = posX - rect.left - handle.offsetWidth / 2; const max = slider.offsetWidth - handle.offsetWidth; if (x < 0) x = 0; if (x > max) x = max; // Prevent moving left of the maximum reached X (user can't undo) // This makes the handle non-decreasing in left position. x = Math.max(x, maxReachedX); // Update maxReachedX to the new position maxReachedX = Math.max(maxReachedX, x); handle.style.left = x + "px"; const slide = x / max; // Girl moves toward center girl.style.transform = `translateX(${slide * 160}px)`; // top text crossfade — but once user has started sliding we lock title updates to avoid audio fighting slider if (!titleLockedByUser) { // smooth crossfade while user slides BEFORE lock text1.style.opacity = 1 - slide; text2.style.opacity = slide; } else { // If locked, ensure title remains the user's chosen state. // Prefer always-forever look when user has moved beyond tiny threshold if (slide > 0.2) { text1.style.opacity = 0; text2.style.opacity = 1; } else { text1.style.opacity = 1; text2.style.opacity = 0; } } // hug appears when close to end visually if (slide > 0.85) { girl.style.opacity = 0; boy.style.opacity = 0; hug.style.opacity = 1; } else { girl.style.opacity = 1; boy.style.opacity = 1; hug.style.opacity = 0; } // reveal lyrics panel when the user starts sliding if (!startedBySlide && slide > 0.01) { startedBySlide = true; // lock title so audio.timeupdate won't fight the slider and cause flicker titleLockedByUser = true; revealLyricsAndStart(); } } /* ---------- reveal lyrics + start audio ---------- */ function revealLyricsAndStart() { // show lyrics panel lyricsPanel.style.display = "block"; // start audio if not already playing if (audio.src && audio.paused) { audio.play().catch(err => { console.warn("Autoplay blocked; user gesture needed to play. Click Play manually.", err); }); } // (Optional) while the user has started sliding, keep the top title in the "song title" state: text1.style.opacity = 0; text2.style.opacity = 1; } /* ---------- audio sync for top text & lyrics ---------- */ audio.addEventListener("timeupdate", () => { const t = audio.currentTime; // 1) top text auto-switch based on CONFIG.titleChangeTime // Only let audio control the title if the user hasn't locked it by sliding. if (typeof CONFIG.titleChangeTime === "number" && !titleLockedByUser) { if (t >= CONFIG.titleChangeTime) { text1.style.opacity = 0; text2.style.opacity = 1; } else { text1.style.opacity = 1; text2.style.opacity = 0; } } // 2) highlight current lyric line (line-by-line) if (lines.length === 0) return; for (let i = 0; i < lines.length; i++) { const current = lines[i]; const next = lines[i+1]; if (t >= current.time && (!next || t < next.time)) { highlightLine(i); break; } } }); /* ---------- highlight and scroll the lyrics box ---------- */ let lastActive = -1; function highlightLine(index) { if (index === lastActive) return; lastActive = index; const all = lyricsDiv.querySelectorAll("p"); all.forEach(p => p.classList.remove("active")); const el = document.getElementById("line-" + index); if (!el) return; el.classList.add("active"); // auto-scroll lyricsPanel so active line is centered-ish const panel = lyricsPanel; const topOffset = el.offsetTop - panel.clientHeight/2 + el.clientHeight/2; panel.scrollTo({ top: Math.max(0, topOffset), behavior: "smooth" }); } /* ---------- handle audio ended: keep locked state if user locked it ---------- */ audio.addEventListener("ended", () => { if (!titleLockedByUser) { // reset top text and visuals only if user didn't lock by sliding text1.style.opacity = 1; text2.style.opacity = 0; handle.style.left = "0px"; girl.style.transform = `translateX(0px)`; girl.style.opacity = 1; boy.style.opacity = 1; hug.style.opacity = 0; setTimeout(() => { lyricsPanel.style.display = "none"; lastActive = -1; maxReachedX = 0; }, 900); } else { // user locked: keep state (do not reset). Also disable handle pointer events so user can't attempt to move left. handle.style.pointerEvents = 'none'; // keep lyrics visible (you can change to hide if you want) } }); /* ---------- optional: click play from UI will also reveal lyrics (if they want) ---------- */ audio.addEventListener("play", () => { // if user presses play without sliding, we still want top sync and optionally reveal lyrics: // For now we won't auto-show lyrics unless they've dragged — that was requested by you. }); /* ---------- small safety: if user hasn't provided LRC/audio links, leave working structure ---------- */ </script> </body> </html> |