Add smooth parallax background pan

This commit is contained in:
2026-02-03 01:15:33 +01:00
parent 84ebc25340
commit bb810584ee
2 changed files with 47 additions and 4 deletions

View File

@@ -8,6 +8,7 @@ import {
} from "./js/i18n.js"; } from "./js/i18n.js";
initI18n(); initI18n();
setupBackgroundPan();
const state = { const state = {
isAuthenticated: false, isAuthenticated: false,
@@ -836,6 +837,42 @@ function setupCardVisualHover(el, url) {
["mouseleave", "blur"].forEach((evt) => el.addEventListener(evt, reset)); ["mouseleave", "blur"].forEach((evt) => el.addEventListener(evt, reset));
} }
function setupBackgroundPan(config = {}) {
const root = document.documentElement;
const maxOffset = config.maxOffsetPx ?? 30;
const ease = config.ease ?? 0.08;
if (config.scalePercent) {
root.style.setProperty("--bg-scale", config.scalePercent);
}
let targetX = 0;
let targetY = 0;
let currX = 0;
let currY = 0;
const setTarget = (x, y) => {
targetX = x;
targetY = y;
};
const step = () => {
currX += (targetX - currX) * ease;
currY += (targetY - currY) * ease;
root.style.setProperty("--bg-x", `${currX}px`);
root.style.setProperty("--bg-y", `${currY}px`);
requestAnimationFrame(step);
};
window.addEventListener("mousemove", (e) => {
const nx = (e.clientX / window.innerWidth - 0.5) * 2;
const ny = (e.clientY / window.innerHeight - 0.5) * 2;
setTarget(nx * maxOffset, ny * maxOffset);
});
window.addEventListener("mouseleave", () => setTarget(0, 0));
window.addEventListener("blur", () => setTarget(0, 0));
step();
}
async function main() { async function main() {
setupHandlers(); setupHandlers();
try { try {
@@ -897,7 +934,7 @@ function scoreToEmoji(score) {
} }
function neutralEmoji() { function neutralEmoji() {
return "⬅️"; return "😐";
} }
function signatureSuggestions(list) { function signatureSuggestions(list) {

View File

@@ -8,6 +8,9 @@
sans-serif; sans-serif;
background: #f6e9d6; background: #f6e9d6;
color: #2c1c0d; color: #2c1c0d;
--bg-scale: 115%;
--bg-x: 0px;
--bg-y: 0px;
} }
*, *,
@@ -24,9 +27,12 @@
align-items: center; align-items: center;
gap: 16px; gap: 16px;
min-height: 100vh; min-height: 100vh;
background: background-color: #f6e9d6;
url("background.png") center/cover no-repeat fixed, background-image: url("background.png");
#f6e9d6; background-repeat: no-repeat;
background-attachment: fixed;
background-size: var(--bg-scale) var(--bg-scale);
background-position: calc(50% + var(--bg-x)) calc(50% + var(--bg-y));
} }
.lang-field { .lang-field {