Вход с молнией
Форма входа, освещённая шаровой молнией. Она зависает над активным полем и бьёт разрядом при каждом нажатии клавиши. Неверный пароль вызывает короткое замыкание и искры, верный заряжает кнопку.
- Вход и формы
- Бесплатно
- canvas
- spring
- Добавлен 29 сентября 2026
<style>
/* Volt Login by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file */
/* a soft dark around the form, the ball carries an electric light; --r grows and shrinks with its charge */
.night { position: fixed; inset: 0; z-index: 5; pointer-events: none; transition: opacity .6s ease;
background: radial-gradient(circle at var(--x, -200px) var(--y, 30%), rgba(230,255,79,.07) 0, rgba(7,8,10,.22) calc(var(--r, 260px) * .5), rgba(7,8,10,.52) var(--r, 260px)); }
.night.day { opacity: .3; }
.sky { position: fixed; inset: 0; z-index: 6; width: 100%; height: 100%; pointer-events: none; mix-blend-mode: screen; } /* strikes and sparks add light */
.login { position: relative; box-sizing: border-box; width: min(360px, 92vw); display: grid; gap: 16px; margin: 0; }
.field { position: relative; height: 52px; border-radius: 14px; background: #121410; overflow: hidden; box-shadow: inset 0 0 0 1.2px rgba(235,255,200,.1); }
.field:focus-within, .field.lit { box-shadow: inset 0 0 0 1.6px rgba(230,255,79,.9), 0 0 0 4px rgba(230,255,79,.14); }
.field input { position: relative; box-sizing: border-box; width: 100%; height: 100%; padding: 0 52px 0 18px; border: 0; outline: 0; background: transparent;
font: 500 16px system-ui, sans-serif; color: #F2F4EC; caret-color: #E6FF4F; }
.field input::placeholder { color: rgba(205,210,190,.45); }
/* password: the real input stays type="password", what you see is drawn next to it */
.pass input { color: transparent; caret-color: transparent; }
.mirror { position: absolute; left: 18px; right: 52px; top: 0; bottom: 0; pointer-events: none; overflow: hidden; font: 500 16px system-ui, sans-serif; }
.dots, .text { position: absolute; left: 0; top: 0; bottom: 0; display: flex; align-items: center; white-space: pre;
transition: opacity .3s cubic-bezier(.77, 0, .175, 1), filter .3s cubic-bezier(.77, 0, .175, 1); }
.dots i { flex: none; width: 14px; height: 14px; display: grid; place-items: center; }
.dots i::after { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #F2F4EC; }
.text { opacity: 0; filter: blur(3px); letter-spacing: .5px; }
.text b { font-weight: 500; }
.show .dots { opacity: 0; filter: blur(3px); }
.show .text { opacity: 1; filter: none; }
.dots i.new, .text b.new { animation: zap .4s cubic-bezier(.23, 1, .32, 1); }
@keyframes zap { from { filter: drop-shadow(0 0 6px #E6FF4F) brightness(2); } }
/* a short circuit: the dots glow orange and burn out one after another */
.pass.burn .dots i::after, .pass.burn .text b { animation: burn .45s cubic-bezier(.45, 0, .55, 1) calc(var(--i, 0) * 40ms) forwards; }
@keyframes burn { 30% { background: #FF9A7A; color: #FF9A7A; box-shadow: 0 0 8px #FF9A7A; } to { background: #FF9A7A; color: #FF9A7A; box-shadow: 0 0 8px rgba(255,154,122,0); scale: .5; opacity: 0; } }
.pass.burn input::placeholder { color: transparent; }
.caret { position: absolute; left: 0; top: 16px; width: 2px; height: 20px; background: #E6FF4F; opacity: 0; }
.pass:focus-within .caret { opacity: 1; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.eye { position: absolute; right: 8px; top: 8px; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 10px; background: transparent;
display: grid; place-items: center; cursor: pointer; color: rgba(228,232,215,.55); transition: color .2s ease, transform .16s ease-out; }
.eye:active { transform: scale(.94); }
.eye:focus-visible { outline: 2px solid #E6FF4F; outline-offset: 1px; }
.eye svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.eye .slash { stroke-dasharray: 26; stroke-dashoffset: 0; transition: stroke-dashoffset .25s cubic-bezier(.23, 1, .32, 1); }
.show .eye { color: #E6FF4F; }
.show .eye .slash { stroke-dashoffset: 26; }
.note { position: absolute; left: 4px; top: 128px; margin: 0; font: 600 13px system-ui, sans-serif; color: #FF9A7A; opacity: 0; transform: translateY(-4px);
transition: opacity .2s ease-out, transform .2s ease-out; pointer-events: none; }
.note.on { opacity: 1; transform: none; }
/* the button charges up from the point where the ball went in */
.send { position: relative; height: 54px; margin-top: 10px; border: 0; border-radius: 27px; background: #171A13; box-shadow: inset 0 0 0 1.2px rgba(240,255,210,.10);
color: #EDF0E4; font: 600 16px system-ui, sans-serif; cursor: pointer; overflow: hidden; transition: transform .16s ease-out; }
.send:active { transform: scale(.97); }
.send:focus-visible { outline: 2px solid #E6FF4F; outline-offset: 3px; }
.send::before { content: ""; position: absolute; inset: 0; background: linear-gradient(#F6FFB8, #D3F53A);
clip-path: circle(0 at var(--hx, 50%) 50%); transition: clip-path .5s cubic-bezier(.23, 1, .32, 1); }
.send.done::before { clip-path: circle(150% at var(--hx, 50%) 50%); }
.send.still::before, .send.still span { transition: none; }
.send span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 8px;
transition: opacity .3s ease-out, filter .3s ease-out, transform .3s cubic-bezier(.23, 1, .32, 1); }
.send .ok { color: #1D2500; opacity: 0; filter: blur(3px); transform: translateY(6px); }
.send .ok svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.send.done .go { opacity: 0; filter: blur(3px); transform: translateY(-6px); }
.send.done .ok { opacity: 1; filter: none; transform: none; transition-delay: .16s; }
@media (hover: hover) and (pointer: fine) {
.send:not(.done):hover { background: #1D2118; }
}
</style>
<div class="night" aria-hidden="true"></div>
<canvas class="sky" aria-hidden="true"></canvas>
<form class="login" novalidate>
<div class="field mail">
<input id="email" type="email" name="email" placeholder="Email" autocomplete="username" aria-label="Email">
</div>
<div class="field pass">
<input id="pass" type="password" name="password" placeholder="Password" autocomplete="current-password" aria-label="Password">
<span class="mirror" aria-hidden="true"><span class="dots"></span><span class="text"></span><i class="caret"></i></span>
<button class="eye" type="button" aria-label="Show password" aria-pressed="false">
<svg viewBox="0 0 24 24"><path d="M1.5 12S5.5 4.5 12 4.5 22.5 12 22.5 12 18.5 19.5 12 19.5 1.5 12 1.5 12Z"/><circle cx="12" cy="12" r="3.2"/><path class="slash" d="M3.5 20.5 20.5 3.5"/></svg>
</button>
</div>
<p class="note" aria-live="polite"></p>
<button class="send" type="submit">
<span class="go">Sign in</span>
<span class="ok"><svg viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>You're in</span>
</button>
</form>
<script>
// Volt Login by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file
const STIFF = 0.08, DAMP = 0.7, ARCS = 4;
// after a wrong password the light sags by SAG, one number per 0.15 s, blended in between
const SAG = [1, .45, .12, 0, .3, .1, .65, 1];
const DEMO_PASSWORD = 'thunder'; // the demo's only right answer, delete it once your server checks
const $ = s => document.querySelector(s);
const form = $('.login'), email = $('#email'), pass = $('#pass'), eye = $('.eye'), send = $('.send'), note = $('.note');
const mailField = email.parentElement, passField = pass.parentElement;
const night = $('.night'), dots = $('.dots'), text = $('.text'), caret = $('.caret');
const sky = $('.sky'), g = sky.getContext('2d');
const reduce = matchMedia('(prefers-reduced-motion: reduce)').matches;
const wait = ms => new Promise(r => setTimeout(r, ms));
const clamp = (v, a = 0, b = 1) => Math.min(b, Math.max(a, v));
const pen = document.createElement('canvas').getContext('2d');
pen.font = '500 16px system-ui, sans-serif';
// one strike of lightning: split the line in two at a jittered middle until the pieces are tiny
const WILD = reduce ? 0 : 1; // with reduced motion every strike is a straight line
const shake = r => (Math.random() - .5) * r;
function bolt(a, b, r) {
if (r < 2) return g.lineTo(b.x, b.y);
const m = { x: (a.x + b.x) / 2 + shake(r),
y: (a.y + b.y) / 2 + shake(r) };
bolt(a, m, r / 2); bolt(m, b, r / 2);
}
// where the ball hovers for each element: just above a field, in the middle of a button
function at(el) {
const r = el.getBoundingClientRect();
if (el === email || el === pass) return { x: r.left + 30, y: r.top - 26 };
return { x: r.left + r.width / 2, y: r.top + r.height / 2 };
}
// the spot a key strikes: the last character of the field
function spot(input) {
const r = input.getBoundingClientRect(), v = input.value;
const w = input === email ? pen.measureText(v).width
: passField.classList.contains('show') ? pen.measureText(v).width + v.length * .5 : v.length * 14 - 7;
return { x: r.left + 18 + Math.min(Math.max(w, 6), r.width - 70), y: r.top + r.height / 2 };
}
const above = p => ({ x: p.x + 6, y: p.y - 52 });
// it starts just off the email field and flies in, so it crackles in the frame from the start
let goal = above(spot(email)), x = goal.x - 60, y = goal.y - 30, vx = 0, vy = 0;
let hit = null, shortAt = -1e4, charged = null, inside = false, vis = 1, away = false, dpr = 1;
let last = performance.now(), acc = 0;
const sparks = [];
function size() {
dpr = Math.min(2, devicePixelRatio || 1);
sky.width = innerWidth * dpr; sky.height = innerHeight * dpr;
}
addEventListener('resize', size); size();
const strike = p => { hit = { x: p.x, y: p.y, at: performance.now() }; };
// how much charge it has; a frame can start a little before the answer came, so s < 0 counts as full light
function light(now) {
const s = (now - shortAt) / 150, i = Math.floor(s);
if (reduce || s < 0 || i >= SAG.length - 1) return 1;
return SAG[i] + (SAG[i + 1] - SAG[i]) * (s - i);
}
// how orange it is: comes in over .15 s, holds while the light sags, goes over .3 s
const heat = now => { const s = (now - shortAt) / 1000; return s < 0 ? 0 : clamp(s / .15) * clamp((1.05 - s) / .3); };
const mix = (a, b, k) => a.map((v, i) => Math.round(v + (b[i] - v) * k)).join();
(function fly(now = performance.now()) {
acc += Math.min(100, now - last); last = now;
for (; acc >= 1000 / 60; acc -= 1000 / 60) {
vx = (vx + (goal.x - x) * STIFF) * DAMP;
vy = (vy + (goal.y - y) * STIFF) * DAMP;
x += vx; y += vy;
vis += ((away ? 0 : 1) - vis) * .035; // it fades out like ball lightning when it leaves
for (const p of sparks) { p.x += p.vx; p.y += p.vy; p.vx *= .95; p.vy = p.vy * .95 + .05; p.age += 1 / 60; } // they slow down and settle
}
for (let i = sparks.length - 1; i >= 0; i--) if (sparks[i].age >= sparks[i].life) sparks.splice(i, 1);
const k = light(now);
night.style.setProperty('--x', x + 'px');
night.style.setProperty('--y', y + 'px');
night.style.setProperty('--r', (260 * (.4 + .6 * k) * (.35 + .65 * vis)).toFixed(1) + 'px');
draw(now, k);
requestAnimationFrame(fly);
})();
function stroke(width, color) { g.lineWidth = width; g.strokeStyle = color; g.stroke(); }
function draw(now, k) {
g.setTransform(dpr, 0, 0, dpr, 0, 0);
g.clearRect(0, 0, innerWidth, innerHeight);
g.globalCompositeOperation = 'lighter';
g.lineCap = g.lineJoin = 'round';
const here = { x, y }, h = heat(now), pulse = reduce ? 1 : .86 + .14 * Math.sin(now / 1000 * 5.2), arc = mix([240, 255, 170], [255, 190, 150], h);
if (k > .1 && !inside && vis > .1) {
for (let i = 0; i < ARCS; i++) { // the little arcs that crackle round the ball
const a = reduce ? i * 1.57 : Math.random() * 7, len = 12 + (reduce ? 6 : Math.random() * 12);
g.beginPath(); g.moveTo(x, y); bolt(here, { x: x + Math.cos(a) * len, y: y + Math.sin(a) * len }, 10 * WILD);
stroke(1.2, `rgba(${arc},${(.7 * k * vis).toFixed(3)})`);
}
}
const age = hit ? (now - hit.at) / 1000 : 9;
if (age < .12 && k > .1) { // a strike: a wide glow, then the white-hot core
const path = () => { g.beginPath(); g.moveTo(x, y); bolt(here, hit, 26 * WILD); };
path(); stroke(6, 'rgba(230,255,79,.22)');
path(); stroke(1.6, 'rgba(250,255,225,.95)');
const f = g.createRadialGradient(hit.x, hit.y, 0, hit.x, hit.y, 22);
f.addColorStop(0, `rgba(240,255,160,${(.6 * (1 - age / .12)).toFixed(3)})`); f.addColorStop(1, 'rgba(230,255,79,0)');
g.fillStyle = f; g.fillRect(hit.x - 22, hit.y - 22, 44, 44);
}
const ss = (now - shortAt) / 1000;
if (ss >= 0 && ss < .4) { // the short: orange arcs crackle over the button for a moment
const r = send.getBoundingClientRect();
for (let i = 0; i < 3; i++) {
const ax = r.left + 20 + Math.random() * (r.width - 40), bx = ax + (Math.random() - .5) * 90;
g.beginPath(); g.moveTo(ax, r.top + 8); bolt({ x: ax, y: r.top + 8 }, { x: bx, y: r.bottom - 8 }, 18 * WILD);
stroke(1.4, `rgba(255,170,130,${(.9 * (1 - ss / .4)).toFixed(3)})`);
}
}
if (charged !== null) { // after sign in, arcs crawl over the button for a moment
const s = (now - charged) / 1000, r = send.getBoundingClientRect();
if (s < .9) for (let i = 0; i < 3; i++) {
const ax = r.left + 20 + Math.random() * (r.width - 40), bx = ax + (Math.random() - .5) * 90;
g.beginPath(); g.moveTo(ax, r.top + 8); bolt({ x: ax, y: r.top + 8 }, { x: bx, y: r.bottom - 8 }, 18 * WILD);
stroke(1.4, `rgba(255,255,230,${(.9 * (1 - s / .9)).toFixed(3)})`);
}
}
for (const p of sparks) { // sparks twinkle and settle
const al = (1 - p.age / p.life) * (reduce ? 1 : .6 + .4 * Math.sin(p.age * 14 + p.r * 9)), c = p.hot ? '255,190,150' : '240,255,170';
const d = g.createRadialGradient(p.x, p.y, 0, p.x, p.y, p.r * 3.5);
d.addColorStop(0, `rgba(${c},${al.toFixed(3)})`); d.addColorStop(1, `rgba(${c},0)`);
g.fillStyle = d; g.fillRect(p.x - p.r * 3.5, p.y - p.r * 3.5, p.r * 7, p.r * 7);
}
if (inside) { // inside the button it still shows, a dim core and its light through the surface
const r = send.getBoundingClientRect();
g.save(); g.beginPath(); g.roundRect(r.left, r.top, r.width, r.height, r.height / 2); g.clip();
const u = g.createRadialGradient(x, y, 0, x, y, 60);
u.addColorStop(0, `rgba(240,255,170,${(.45 * k).toFixed(3)})`); u.addColorStop(1, 'rgba(230,255,79,0)');
g.fillStyle = u; g.fillRect(x - 60, y - 60, 120, 120); g.restore();
g.fillStyle = `rgba(255,255,245,${(.35 * k).toFixed(3)})`; g.beginPath(); g.arc(x, y, 4, 0, 7); g.fill();
} else if (vis > .01) { // the ball itself, breathing; orange while it is shorted
const lv = k * pulse * vis;
for (const [on, c] of [[1 - h, ['245,255,190', '230,255,79']], [h, ['255,215,190', '255,154,122']]]) {
if (on <= 0) continue;
const glow = g.createRadialGradient(x, y, 0, x, y, 46);
glow.addColorStop(0, `rgba(${c[0]},${(.9 * lv * on).toFixed(3)})`); glow.addColorStop(.25, `rgba(${c[1]},${(.35 * lv * on).toFixed(3)})`); glow.addColorStop(1, `rgba(${c[1]},0)`);
g.fillStyle = glow; g.fillRect(x - 46, y - 46, 92, 92);
}
g.fillStyle = `rgba(255,255,245,${((.35 + .65 * k) * vis).toFixed(3)})`; g.beginPath(); g.arc(x, y, 5, 0, 7); g.fill();
}
}
const follow = el => () => goal = el === email || el === pass ? above(spot(el)) : at(el);
for (const el of [email, pass, eye, send])
el.onfocus = el.onclick = follow(el);
email.addEventListener('input', () => { const p = spot(email); goal = above(p); strike(p); });
function paintPassword(fresh) {
const v = [...pass.value], mark = (node, i) => { if (fresh && i === v.length - 1) node.className = 'new'; return node; };
dots.replaceChildren(...v.map((_, i) => { const d = mark(document.createElement('i'), i); d.style.setProperty('--i', i); return d; }));
text.replaceChildren(...v.map((ch, i) => { const b = mark(document.createElement('b'), i); b.textContent = ch; b.style.setProperty('--i', i); return b; }));
caret.style.translate = (passField.classList.contains('show') ? text.offsetWidth : v.length * 14) + 'px 0';
}
pass.addEventListener('input', () => {
clearTimeout(burnT); passField.classList.remove('burn'); note.classList.remove('on'); paintPassword(true);
const p = spot(pass); goal = above(p); if (pass.value) strike(p);
});
eye.addEventListener('click', () => {
const on = passField.classList.toggle('show');
eye.setAttribute('aria-pressed', on);
eye.setAttribute('aria-label', on ? 'Hide password' : 'Show password');
paintPassword(false);
const r = eye.getBoundingClientRect(), p = { x: r.left + r.width / 2, y: r.top + r.height / 2 };
goal = above(p); strike(p);
});
// a wrong password: the light sags and comes back, orange sparks drift down, the dots burn out and the ball climbs back
let burnT;
function shortCircuit() {
shortAt = performance.now(); inside = false;
if (!reduce) for (let i = 0; i < 14; i++)
sparks.push({ x, y, vx: (Math.random() - .5) * 4, vy: -(1 + 2.5 * Math.random()), age: 0, life: 1.2 + .6 * Math.random(), r: 1 + Math.random(), hot: 1 });
note.textContent = 'Wrong password'; note.classList.add('on');
pass.value = ''; passField.classList.add('burn');
clearTimeout(burnT); burnT = setTimeout(() => { passField.classList.remove('burn'); paintPassword(false); }, 600);
pass.focus(); goal = above(spot(pass));
}
async function signIn(login, password) {
// a real request goes here, for example:
// const res = await fetch('/api/login', {
// method: 'POST',
// headers: { 'Content-Type': 'application/json' },
// body: JSON.stringify({ login, password }),
// });
// return res.ok;
await wait(250);
return password === DEMO_PASSWORD;
}
let round = 0; // grows on every submit and reset, so a late answer can tell it's stale
form.addEventListener('submit', async e => {
e.preventDefault();
if (send.classList.contains('done')) return;
const empty = !email.value ? email : !pass.value ? pass : null;
if (empty) { goal = above(spot(empty)); empty.focus(); return; }
goal = at(send);
const mine = ++round, answer = signIn(email.value, pass.value);
await wait(200); if (mine !== round) return;
inside = true; // the ball goes into the button
const [ok] = await Promise.all([answer, wait(100)]);
if (mine !== round) return;
if (!ok) return shortCircuit();
send.style.setProperty('--hx', x - send.getBoundingClientRect().left + 'px');
send.classList.add('done');
night.classList.add('day');
charged = performance.now();
const b = send.getBoundingClientRect();
if (!reduce) for (let i = 0; i < 24; i++) { // the charged button throws electric sparks that slow down and settle
const a = -Math.PI / 2 + (Math.random() - .5) * 2.6, v = 1.8 + 3.2 * Math.random();
sparks.push({ x: b.left + 20 + Math.random() * (b.width - 40), y: b.top + 6, vx: Math.cos(a) * v * 1.2, vy: Math.sin(a) * v, age: 0, life: 1.4 + Math.random(), r: .9 + 1.1 * Math.random(), hot: 0 });
}
await wait(750);
inside = false;
const r = send.getBoundingClientRect();
goal = { x: r.left + r.width * .66, y: r.top - 22 };
});
// optional demo: call play() to auto-type; stops on click or key
let demo = false;
const stopDemo = () => {
if (!demo) return;
demo = false;
mailField.classList.remove('lit');
reset();
};
addEventListener('pointerdown', stopDemo, true);
addEventListener('keydown', stopDemo, true);
function reset() {
round++; away = false;
clearTimeout(burnT); shortAt = -1e4; sparks.length = 0;
email.value = pass.value = '';
passField.classList.remove('show', 'burn'); eye.setAttribute('aria-pressed', false);
send.classList.add('still'); send.classList.remove('done'); // back to Sign in at once, no unfilling
requestAnimationFrame(() => requestAnimationFrame(() => send.classList.remove('still')));
night.classList.remove('day'); note.classList.remove('on');
paintPassword(false); inside = false; charged = null;
}
async function typeInto(input, word, gap) {
for (const ch of word) {
if (!demo) return false;
input.value += ch; input.dispatchEvent(new Event('input'));
await wait(gap);
}
return demo;
}
async function play() {
demo = true;
await wait(200); if (!demo) return;
mailField.classList.add('lit');
if (!await typeInto(email, 'you@example.com', 42)) return;
await wait(60); if (!demo) return;
mailField.classList.remove('lit'); pass.focus();
await wait(90); if (!demo) return;
if (!await typeInto(pass, 'zap', 72)) return;
form.requestSubmit(); // a wrong one first: a short circuit
await wait(920); if (!demo) return;
if (!await typeInto(pass, DEMO_PASSWORD, 72)) return;
await wait(250); if (!demo) return;
eye.click();
await wait(300); if (!demo) return;
form.requestSubmit();
await wait(4000); if (!demo) return;
goal = { x: goal.x + 30, y: goal.y - 60 }; away = true; // it lifts and fades out like ball lightning, the dark comes back
night.classList.remove('day');
await wait(1000); if (!demo) return;
reset();
goal = above(spot(email)); x = goal.x - 60; y = goal.y - 30; vx = vy = 0; // and comes back over the email field
await wait(1400); if (demo) play();
}
</script>
Нажмите на поле Email и введите текст. Для пароля попробуйте сначала zap, затем thunder и нажмите Sign in.
Что можно поменять
Поменяйте число, сохраните файл и обновите страницу, разница будет видна сразу.
STIFF0.08Насколько сильно шаровая молния тянется к цели, чем выше тем быстрее.
DAMP0.7Как быстро она успокаивается, ближе к 1 движение более прыгучее.
ARCS4Сколько мелких дуг потрескивает вокруг шара.
bolt(a, b, r)26Насколько резкий разряд, молния дробится пока отрезки не станут меньше 2px.
SAG[1, .45, .12, 0, .3, .1, .65, 1]Кривая просадки и возврата света после неверного пароля.
DEMO_PASSWORD'thunder'Пароль для демо: неверный вызывает сбой, верный открывает вход.
Как поставить на свой сайт
Поставьте на экран входа. Сцена хорошо читается на тёмном фоне.
Комментарии в коде на английском, так файл понятен любому разработчику.
CSS
Вставьте в свой файл стилей или в тег <style> внутри <head>.
/* Volt Login by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file */ /* a soft dark around the form, the ball carries an electric light; --r grows and shrinks with its charge */ .night { position: fixed; inset: 0; z-index: 5; pointer-events: none; transition: opacity .6s ease; background: radial-gradient(circle at var(--x, -200px) var(--y, 30%), rgba(230,255,79,.07) 0, rgba(7,8,10,.22) calc(var(--r, 260px) * .5), rgba(7,8,10,.52) var(--r, 260px)); } .night.day { opacity: .3; } .sky { position: fixed; inset: 0; z-index: 6; width: 100%; height: 100%; pointer-events: none; mix-blend-mode: screen; } /* strikes and sparks add light */ .login { position: relative; box-sizing: border-box; width: min(360px, 92vw); display: grid; gap: 16px; margin: 0; } .field { position: relative; height: 52px; border-radius: 14px; background: #121410; overflow: hidden; box-shadow: inset 0 0 0 1.2px rgba(235,255,200,.1); } .field:focus-within, .field.lit { box-shadow: inset 0 0 0 1.6px rgba(230,255,79,.9), 0 0 0 4px rgba(230,255,79,.14); } .field input { position: relative; box-sizing: border-box; width: 100%; height: 100%; padding: 0 52px 0 18px; border: 0; outline: 0; background: transparent; font: 500 16px system-ui, sans-serif; color: #F2F4EC; caret-color: #E6FF4F; } .field input::placeholder { color: rgba(205,210,190,.45); } /* password: the real input stays type="password", what you see is drawn next to it */ .pass input { color: transparent; caret-color: transparent; } .mirror { position: absolute; left: 18px; right: 52px; top: 0; bottom: 0; pointer-events: none; overflow: hidden; font: 500 16px system-ui, sans-serif; } .dots, .text { position: absolute; left: 0; top: 0; bottom: 0; display: flex; align-items: center; white-space: pre; transition: opacity .3s cubic-bezier(.77, 0, .175, 1), filter .3s cubic-bezier(.77, 0, .175, 1); } .dots i { flex: none; width: 14px; height: 14px; display: grid; place-items: center; } .dots i::after { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #F2F4EC; } .text { opacity: 0; filter: blur(3px); letter-spacing: .5px; } .text b { font-weight: 500; } .show .dots { opacity: 0; filter: blur(3px); } .show .text { opacity: 1; filter: none; } .dots i.new, .text b.new { animation: zap .4s cubic-bezier(.23, 1, .32, 1); } @keyframes zap { from { filter: drop-shadow(0 0 6px #E6FF4F) brightness(2); } } /* a short circuit: the dots glow orange and burn out one after another */ .pass.burn .dots i::after, .pass.burn .text b { animation: burn .45s cubic-bezier(.45, 0, .55, 1) calc(var(--i, 0) * 40ms) forwards; } @keyframes burn { 30% { background: #FF9A7A; color: #FF9A7A; box-shadow: 0 0 8px #FF9A7A; } to { background: #FF9A7A; color: #FF9A7A; box-shadow: 0 0 8px rgba(255,154,122,0); scale: .5; opacity: 0; } } .pass.burn input::placeholder { color: transparent; } .caret { position: absolute; left: 0; top: 16px; width: 2px; height: 20px; background: #E6FF4F; opacity: 0; } .pass:focus-within .caret { opacity: 1; animation: blink 1s steps(1) infinite; } @keyframes blink { 50% { opacity: 0; } } .eye { position: absolute; right: 8px; top: 8px; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 10px; background: transparent; display: grid; place-items: center; cursor: pointer; color: rgba(228,232,215,.55); transition: color .2s ease, transform .16s ease-out; } .eye:active { transform: scale(.94); } .eye:focus-visible { outline: 2px solid #E6FF4F; outline-offset: 1px; } .eye svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; } .eye .slash { stroke-dasharray: 26; stroke-dashoffset: 0; transition: stroke-dashoffset .25s cubic-bezier(.23, 1, .32, 1); } .show .eye { color: #E6FF4F; } .show .eye .slash { stroke-dashoffset: 26; } .note { position: absolute; left: 4px; top: 128px; margin: 0; font: 600 13px system-ui, sans-serif; color: #FF9A7A; opacity: 0; transform: translateY(-4px); transition: opacity .2s ease-out, transform .2s ease-out; pointer-events: none; } .note.on { opacity: 1; transform: none; } /* the button charges up from the point where the ball went in */ .send { position: relative; height: 54px; margin-top: 10px; border: 0; border-radius: 27px; background: #171A13; box-shadow: inset 0 0 0 1.2px rgba(240,255,210,.10); color: #EDF0E4; font: 600 16px system-ui, sans-serif; cursor: pointer; overflow: hidden; transition: transform .16s ease-out; } .send:active { transform: scale(.97); } .send:focus-visible { outline: 2px solid #E6FF4F; outline-offset: 3px; } .send::before { content: ""; position: absolute; inset: 0; background: linear-gradient(#F6FFB8, #D3F53A); clip-path: circle(0 at var(--hx, 50%) 50%); transition: clip-path .5s cubic-bezier(.23, 1, .32, 1); } .send.done::before { clip-path: circle(150% at var(--hx, 50%) 50%); } .send.still::before, .send.still span { transition: none; } .send span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 8px; transition: opacity .3s ease-out, filter .3s ease-out, transform .3s cubic-bezier(.23, 1, .32, 1); } .send .ok { color: #1D2500; opacity: 0; filter: blur(3px); transform: translateY(6px); } .send .ok svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; } .send.done .go { opacity: 0; filter: blur(3px); transform: translateY(-6px); } .send.done .ok { opacity: 1; filter: none; transform: none; transition-delay: .16s; } @media (hover: hover) and (pointer: fine) { .send:not(.done):hover { background: #1D2118; } }HTML
Поставьте в то место страницы, где должен быть эффект.
<div class="night" aria-hidden="true"></div> <canvas class="sky" aria-hidden="true"></canvas> <form class="login" novalidate> <div class="field mail"> <input id="email" type="email" name="email" placeholder="Email" autocomplete="username" aria-label="Email"> </div> <div class="field pass"> <input id="pass" type="password" name="password" placeholder="Password" autocomplete="current-password" aria-label="Password"> <span class="mirror" aria-hidden="true"><span class="dots"></span><span class="text"></span><i class="caret"></i></span> <button class="eye" type="button" aria-label="Show password" aria-pressed="false"> <svg viewBox="0 0 24 24"><path d="M1.5 12S5.5 4.5 12 4.5 22.5 12 22.5 12 18.5 19.5 12 19.5 1.5 12 1.5 12Z"/><circle cx="12" cy="12" r="3.2"/><path class="slash" d="M3.5 20.5 20.5 3.5"/></svg> </button> </div> <p class="note" aria-live="polite"></p> <button class="send" type="submit"> <span class="go">Sign in</span> <span class="ok"><svg viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>You're in</span> </button> </form>JavaScript
Вставьте перед закрывающим тегом </body>, внутри <script></script>.
// Volt Login by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file const STIFF = 0.08, DAMP = 0.7, ARCS = 4; // after a wrong password the light sags by SAG, one number per 0.15 s, blended in between const SAG = [1, .45, .12, 0, .3, .1, .65, 1]; const DEMO_PASSWORD = 'thunder'; // the demo's only right answer, delete it once your server checks const $ = s => document.querySelector(s); const form = $('.login'), email = $('#email'), pass = $('#pass'), eye = $('.eye'), send = $('.send'), note = $('.note'); const mailField = email.parentElement, passField = pass.parentElement; const night = $('.night'), dots = $('.dots'), text = $('.text'), caret = $('.caret'); const sky = $('.sky'), g = sky.getContext('2d'); const reduce = matchMedia('(prefers-reduced-motion: reduce)').matches; const wait = ms => new Promise(r => setTimeout(r, ms)); const clamp = (v, a = 0, b = 1) => Math.min(b, Math.max(a, v)); const pen = document.createElement('canvas').getContext('2d'); pen.font = '500 16px system-ui, sans-serif'; // one strike of lightning: split the line in two at a jittered middle until the pieces are tiny const WILD = reduce ? 0 : 1; // with reduced motion every strike is a straight line const shake = r => (Math.random() - .5) * r; function bolt(a, b, r) { if (r < 2) return g.lineTo(b.x, b.y); const m = { x: (a.x + b.x) / 2 + shake(r), y: (a.y + b.y) / 2 + shake(r) }; bolt(a, m, r / 2); bolt(m, b, r / 2); } // where the ball hovers for each element: just above a field, in the middle of a button function at(el) { const r = el.getBoundingClientRect(); if (el === email || el === pass) return { x: r.left + 30, y: r.top - 26 }; return { x: r.left + r.width / 2, y: r.top + r.height / 2 }; } // the spot a key strikes: the last character of the field function spot(input) { const r = input.getBoundingClientRect(), v = input.value; const w = input === email ? pen.measureText(v).width : passField.classList.contains('show') ? pen.measureText(v).width + v.length * .5 : v.length * 14 - 7; return { x: r.left + 18 + Math.min(Math.max(w, 6), r.width - 70), y: r.top + r.height / 2 }; } const above = p => ({ x: p.x + 6, y: p.y - 52 }); // it starts just off the email field and flies in, so it crackles in the frame from the start let goal = above(spot(email)), x = goal.x - 60, y = goal.y - 30, vx = 0, vy = 0; let hit = null, shortAt = -1e4, charged = null, inside = false, vis = 1, away = false, dpr = 1; let last = performance.now(), acc = 0; const sparks = []; function size() { dpr = Math.min(2, devicePixelRatio || 1); sky.width = innerWidth * dpr; sky.height = innerHeight * dpr; } addEventListener('resize', size); size(); const strike = p => { hit = { x: p.x, y: p.y, at: performance.now() }; }; // how much charge it has; a frame can start a little before the answer came, so s < 0 counts as full light function light(now) { const s = (now - shortAt) / 150, i = Math.floor(s); if (reduce || s < 0 || i >= SAG.length - 1) return 1; return SAG[i] + (SAG[i + 1] - SAG[i]) * (s - i); } // how orange it is: comes in over .15 s, holds while the light sags, goes over .3 s const heat = now => { const s = (now - shortAt) / 1000; return s < 0 ? 0 : clamp(s / .15) * clamp((1.05 - s) / .3); }; const mix = (a, b, k) => a.map((v, i) => Math.round(v + (b[i] - v) * k)).join(); (function fly(now = performance.now()) { acc += Math.min(100, now - last); last = now; for (; acc >= 1000 / 60; acc -= 1000 / 60) { vx = (vx + (goal.x - x) * STIFF) * DAMP; vy = (vy + (goal.y - y) * STIFF) * DAMP; x += vx; y += vy; vis += ((away ? 0 : 1) - vis) * .035; // it fades out like ball lightning when it leaves for (const p of sparks) { p.x += p.vx; p.y += p.vy; p.vx *= .95; p.vy = p.vy * .95 + .05; p.age += 1 / 60; } // they slow down and settle } for (let i = sparks.length - 1; i >= 0; i--) if (sparks[i].age >= sparks[i].life) sparks.splice(i, 1); const k = light(now); night.style.setProperty('--x', x + 'px'); night.style.setProperty('--y', y + 'px'); night.style.setProperty('--r', (260 * (.4 + .6 * k) * (.35 + .65 * vis)).toFixed(1) + 'px'); draw(now, k); requestAnimationFrame(fly); })(); function stroke(width, color) { g.lineWidth = width; g.strokeStyle = color; g.stroke(); } function draw(now, k) { g.setTransform(dpr, 0, 0, dpr, 0, 0); g.clearRect(0, 0, innerWidth, innerHeight); g.globalCompositeOperation = 'lighter'; g.lineCap = g.lineJoin = 'round'; const here = { x, y }, h = heat(now), pulse = reduce ? 1 : .86 + .14 * Math.sin(now / 1000 * 5.2), arc = mix([240, 255, 170], [255, 190, 150], h); if (k > .1 && !inside && vis > .1) { for (let i = 0; i < ARCS; i++) { // the little arcs that crackle round the ball const a = reduce ? i * 1.57 : Math.random() * 7, len = 12 + (reduce ? 6 : Math.random() * 12); g.beginPath(); g.moveTo(x, y); bolt(here, { x: x + Math.cos(a) * len, y: y + Math.sin(a) * len }, 10 * WILD); stroke(1.2, `rgba(${arc},${(.7 * k * vis).toFixed(3)})`); } } const age = hit ? (now - hit.at) / 1000 : 9; if (age < .12 && k > .1) { // a strike: a wide glow, then the white-hot core const path = () => { g.beginPath(); g.moveTo(x, y); bolt(here, hit, 26 * WILD); }; path(); stroke(6, 'rgba(230,255,79,.22)'); path(); stroke(1.6, 'rgba(250,255,225,.95)'); const f = g.createRadialGradient(hit.x, hit.y, 0, hit.x, hit.y, 22); f.addColorStop(0, `rgba(240,255,160,${(.6 * (1 - age / .12)).toFixed(3)})`); f.addColorStop(1, 'rgba(230,255,79,0)'); g.fillStyle = f; g.fillRect(hit.x - 22, hit.y - 22, 44, 44); } const ss = (now - shortAt) / 1000; if (ss >= 0 && ss < .4) { // the short: orange arcs crackle over the button for a moment const r = send.getBoundingClientRect(); for (let i = 0; i < 3; i++) { const ax = r.left + 20 + Math.random() * (r.width - 40), bx = ax + (Math.random() - .5) * 90; g.beginPath(); g.moveTo(ax, r.top + 8); bolt({ x: ax, y: r.top + 8 }, { x: bx, y: r.bottom - 8 }, 18 * WILD); stroke(1.4, `rgba(255,170,130,${(.9 * (1 - ss / .4)).toFixed(3)})`); } } if (charged !== null) { // after sign in, arcs crawl over the button for a moment const s = (now - charged) / 1000, r = send.getBoundingClientRect(); if (s < .9) for (let i = 0; i < 3; i++) { const ax = r.left + 20 + Math.random() * (r.width - 40), bx = ax + (Math.random() - .5) * 90; g.beginPath(); g.moveTo(ax, r.top + 8); bolt({ x: ax, y: r.top + 8 }, { x: bx, y: r.bottom - 8 }, 18 * WILD); stroke(1.4, `rgba(255,255,230,${(.9 * (1 - s / .9)).toFixed(3)})`); } } for (const p of sparks) { // sparks twinkle and settle const al = (1 - p.age / p.life) * (reduce ? 1 : .6 + .4 * Math.sin(p.age * 14 + p.r * 9)), c = p.hot ? '255,190,150' : '240,255,170'; const d = g.createRadialGradient(p.x, p.y, 0, p.x, p.y, p.r * 3.5); d.addColorStop(0, `rgba(${c},${al.toFixed(3)})`); d.addColorStop(1, `rgba(${c},0)`); g.fillStyle = d; g.fillRect(p.x - p.r * 3.5, p.y - p.r * 3.5, p.r * 7, p.r * 7); } if (inside) { // inside the button it still shows, a dim core and its light through the surface const r = send.getBoundingClientRect(); g.save(); g.beginPath(); g.roundRect(r.left, r.top, r.width, r.height, r.height / 2); g.clip(); const u = g.createRadialGradient(x, y, 0, x, y, 60); u.addColorStop(0, `rgba(240,255,170,${(.45 * k).toFixed(3)})`); u.addColorStop(1, 'rgba(230,255,79,0)'); g.fillStyle = u; g.fillRect(x - 60, y - 60, 120, 120); g.restore(); g.fillStyle = `rgba(255,255,245,${(.35 * k).toFixed(3)})`; g.beginPath(); g.arc(x, y, 4, 0, 7); g.fill(); } else if (vis > .01) { // the ball itself, breathing; orange while it is shorted const lv = k * pulse * vis; for (const [on, c] of [[1 - h, ['245,255,190', '230,255,79']], [h, ['255,215,190', '255,154,122']]]) { if (on <= 0) continue; const glow = g.createRadialGradient(x, y, 0, x, y, 46); glow.addColorStop(0, `rgba(${c[0]},${(.9 * lv * on).toFixed(3)})`); glow.addColorStop(.25, `rgba(${c[1]},${(.35 * lv * on).toFixed(3)})`); glow.addColorStop(1, `rgba(${c[1]},0)`); g.fillStyle = glow; g.fillRect(x - 46, y - 46, 92, 92); } g.fillStyle = `rgba(255,255,245,${((.35 + .65 * k) * vis).toFixed(3)})`; g.beginPath(); g.arc(x, y, 5, 0, 7); g.fill(); } } const follow = el => () => goal = el === email || el === pass ? above(spot(el)) : at(el); for (const el of [email, pass, eye, send]) el.onfocus = el.onclick = follow(el); email.addEventListener('input', () => { const p = spot(email); goal = above(p); strike(p); }); function paintPassword(fresh) { const v = [...pass.value], mark = (node, i) => { if (fresh && i === v.length - 1) node.className = 'new'; return node; }; dots.replaceChildren(...v.map((_, i) => { const d = mark(document.createElement('i'), i); d.style.setProperty('--i', i); return d; })); text.replaceChildren(...v.map((ch, i) => { const b = mark(document.createElement('b'), i); b.textContent = ch; b.style.setProperty('--i', i); return b; })); caret.style.translate = (passField.classList.contains('show') ? text.offsetWidth : v.length * 14) + 'px 0'; } pass.addEventListener('input', () => { clearTimeout(burnT); passField.classList.remove('burn'); note.classList.remove('on'); paintPassword(true); const p = spot(pass); goal = above(p); if (pass.value) strike(p); }); eye.addEventListener('click', () => { const on = passField.classList.toggle('show'); eye.setAttribute('aria-pressed', on); eye.setAttribute('aria-label', on ? 'Hide password' : 'Show password'); paintPassword(false); const r = eye.getBoundingClientRect(), p = { x: r.left + r.width / 2, y: r.top + r.height / 2 }; goal = above(p); strike(p); }); // a wrong password: the light sags and comes back, orange sparks drift down, the dots burn out and the ball climbs back let burnT; function shortCircuit() { shortAt = performance.now(); inside = false; if (!reduce) for (let i = 0; i < 14; i++) sparks.push({ x, y, vx: (Math.random() - .5) * 4, vy: -(1 + 2.5 * Math.random()), age: 0, life: 1.2 + .6 * Math.random(), r: 1 + Math.random(), hot: 1 }); note.textContent = 'Wrong password'; note.classList.add('on'); pass.value = ''; passField.classList.add('burn'); clearTimeout(burnT); burnT = setTimeout(() => { passField.classList.remove('burn'); paintPassword(false); }, 600); pass.focus(); goal = above(spot(pass)); } async function signIn(login, password) { // a real request goes here, for example: // const res = await fetch('/api/login', { // method: 'POST', // headers: { 'Content-Type': 'application/json' }, // body: JSON.stringify({ login, password }), // }); // return res.ok; await wait(250); return password === DEMO_PASSWORD; } let round = 0; // grows on every submit and reset, so a late answer can tell it's stale form.addEventListener('submit', async e => { e.preventDefault(); if (send.classList.contains('done')) return; const empty = !email.value ? email : !pass.value ? pass : null; if (empty) { goal = above(spot(empty)); empty.focus(); return; } goal = at(send); const mine = ++round, answer = signIn(email.value, pass.value); await wait(200); if (mine !== round) return; inside = true; // the ball goes into the button const [ok] = await Promise.all([answer, wait(100)]); if (mine !== round) return; if (!ok) return shortCircuit(); send.style.setProperty('--hx', x - send.getBoundingClientRect().left + 'px'); send.classList.add('done'); night.classList.add('day'); charged = performance.now(); const b = send.getBoundingClientRect(); if (!reduce) for (let i = 0; i < 24; i++) { // the charged button throws electric sparks that slow down and settle const a = -Math.PI / 2 + (Math.random() - .5) * 2.6, v = 1.8 + 3.2 * Math.random(); sparks.push({ x: b.left + 20 + Math.random() * (b.width - 40), y: b.top + 6, vx: Math.cos(a) * v * 1.2, vy: Math.sin(a) * v, age: 0, life: 1.4 + Math.random(), r: .9 + 1.1 * Math.random(), hot: 0 }); } await wait(750); inside = false; const r = send.getBoundingClientRect(); goal = { x: r.left + r.width * .66, y: r.top - 22 }; }); // optional demo: call play() to auto-type; stops on click or key let demo = false; const stopDemo = () => { if (!demo) return; demo = false; mailField.classList.remove('lit'); reset(); }; addEventListener('pointerdown', stopDemo, true); addEventListener('keydown', stopDemo, true); function reset() { round++; away = false; clearTimeout(burnT); shortAt = -1e4; sparks.length = 0; email.value = pass.value = ''; passField.classList.remove('show', 'burn'); eye.setAttribute('aria-pressed', false); send.classList.add('still'); send.classList.remove('done'); // back to Sign in at once, no unfilling requestAnimationFrame(() => requestAnimationFrame(() => send.classList.remove('still'))); night.classList.remove('day'); note.classList.remove('on'); paintPassword(false); inside = false; charged = null; } async function typeInto(input, word, gap) { for (const ch of word) { if (!demo) return false; input.value += ch; input.dispatchEvent(new Event('input')); await wait(gap); } return demo; } async function play() { demo = true; await wait(200); if (!demo) return; mailField.classList.add('lit'); if (!await typeInto(email, 'you@example.com', 42)) return; await wait(60); if (!demo) return; mailField.classList.remove('lit'); pass.focus(); await wait(90); if (!demo) return; if (!await typeInto(pass, 'zap', 72)) return; form.requestSubmit(); // a wrong one first: a short circuit await wait(920); if (!demo) return; if (!await typeInto(pass, DEMO_PASSWORD, 72)) return; await wait(250); if (!demo) return; eye.click(); await wait(300); if (!demo) return; form.requestSubmit(); await wait(4000); if (!demo) return; goal = { x: goal.x + 30, y: goal.y - 60 }; away = true; // it lifts and fades out like ball lightning, the dark comes back night.classList.remove('day'); await wait(1000); if (!demo) return; reset(); goal = above(spot(email)); x = goal.x - 60; y = goal.y - 30; vx = vy = 0; // and comes back over the email field await wait(1400); if (demo) play(); }
Подключение к серверу
Замените локальную проверку пароля на запрос к вашему серверу. При ошибке вызывайте короткое замыкание, при успехе заряд кнопки.
Полезно знать
- Each bolt is one recursive function. It splits the line at a jittered middle, then does the same for both halves until the pieces are under 2px.
- A new bolt is drawn every frame, that's what makes it crackle.
- Every key strikes the last character of the field, the flash fades in 120ms.
- The flight is one spring, 60 steps a second on any screen, the ball hovers above the field it works on.
- A short circuit doesn't blink the page. The light follows SAG, blended between the numbers, orange fades in over the electric glow and back out, the sparks slow down and settle.
- Inside the button the ball still shows, a dim core with its light coming through the surface.
- The canvas is sized to the screen in CSS, so it stays sharp and in place on retina screens.
- With reduced motion turned on the arcs and strikes stay still, the light doesn't sag or breathe and no sparks fall.
Tilda, Webflow, WordPress
Нажмите «Скопировать весь код» вверху и вставьте его в один HTML-блок.
Добавить блок, Другое, T123 HTML-код. Вставьте и сохраните. Проверяйте на опубликованной странице, в редакторе скрипты не запускаются.
Панель Add, Embed. Вставьте и нажмите Save & Close. Свой код работает на опубликованном сайте.
Добавить блок, Произвольный HTML. Вставьте и нажмите «Обновить».



