Вход за запотевшим стеклом

Форма входа за запотевшим окном. Протрите стекло мышью или пальцем, у края чистой полосы соберётся вода, и тяжёлая капля стечёт вниз, оставив прозрачную дорожку.

Ведите мышью по стеклу, и оно протирается, а с зажатой кнопкой протираете всей ладонью. Потом введите любую почту и пароль от шести знаков и нажмите Log in.

Скачать

Что можно поменять

Поменяйте число, сохраните файл и обновите страницу, разница будет видна сразу.

FOG0.9

Насколько густой конденсат, от 0 до 1.

BRUSH36

Ширина протирки в пикселях. С зажатой кнопкой примерно вдвое шире.

FOG_BACK12

За сколько секунд протёртое место запотевает снова, 0 значит стекло остаётся чистым.

DROP_COUNT140

Сколько капель может быть на стекле одновременно.

DROP_FALL1

Как быстро стекает тяжёлая капля, на 2 окно как в дождь.

WRITE'Welcome back.'

Слова, которые появляются на стекле после Log in.

Как поставить на свой сайт

Страница входа или регистрации, личный кабинет, любая страница, которая должна ощущаться как дождливый вечер в городе.

Комментарии в коде на английском, так файл понятен любому разработчику.

  1. CSS

    Вставьте в свой файл стилей или в тег <style> внутри <head>.

    /* Fog Glass Login by @codinvisual · t.me/CodinVisual · page shell, only needed while this file is the whole page */
  2. HTML

    Поставьте в то место страницы, где должен быть эффект.

    <!-- login start -->
    <div class="fg">
      <canvas class="fg-street" aria-hidden="true"></canvas>
      <main class="fg-scene">
        <form class="fg-form" novalidate>
          <h1 class="fg-title">Sign in</h1>
          <div class="fg-wrap">
            <label class="fg-top" for="fg-email">Email</label>
            <input class="fg-field" id="fg-email" type="email" name="email" autocomplete="email" placeholder="you@example.com" required>
          </div>
          <div class="fg-wrap">
            <label class="fg-top" for="fg-pass">Password</label>
            <input class="fg-field" id="fg-pass" type="password" name="password" autocomplete="current-password" placeholder="At least 6 characters" required minlength="6">
          </div>
          <p class="fg-note" role="status" aria-live="polite"></p>
          <button class="fg-btn" type="submit"><span>Log in</span><svg viewBox="0 0 24 24" width="22" height="22" aria-hidden="true"><path d="M4 12h15M13.5 6l6 6-6 6" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
        </form>
      </main>
      <canvas class="fg-glass" aria-hidden="true"></canvas>
      <div class="fg-sheen" aria-hidden="true"></div>
      <div class="fg-grain" aria-hidden="true"></div>
      <p class="fg-hint" aria-hidden="true">Wipe the glass</p>
      <button class="fg-out" type="button" hidden>Sign out</button>
    </div>
    <!-- login end -->
  3. JavaScript

    Вставьте перед закрывающим тегом </body>, внутри <script></script>.

    /* Fog Glass Login by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file */
    (() => {
    const FOG = 0.9;
    const BRUSH = 36;
    const FOG_BACK = 12;
    const DROP_COUNT = 140;
    const DROP_FALL = 1;
    const WRITE = 'Welcome back.';
    
    // the street behind the glass: x, y, size, color, brightness
    const LIGHTS = [
      [.08, .62, .018, '#FFB04F', .9], [.17, .6, .014, '#FFD9A0', .8], [.29, .63, .02, '#FFB04F', .85], [.41, .61, .012, '#FFF1DC', .9],
      [.52, .64, .016, '#FFB04F', .8], [.66, .6, .013, '#FFD9A0', .85], [.79, .62, .019, '#FFB04F', .9], [.91, .6, .012, '#FFF1DC', .8],
      [.12, .44, .022, '#FFE6C2', .42], [.24, .4, .016, '#FFE6C2', .38], [.58, .42, .02, '#FFE6C2', .4], [.86, .38, .024, '#FFE6C2', .42],
      [.36, .33, .03, '#4FC9C2', .5], [.72, .29, .022, '#4FC9C2', .45], [.6, .72, .016, '#FF5B4A', .95], [.645, .722, .016, '#FF5B4A', .95],
      [.18, .78, .09, '#FFB04F', .2], [.84, .82, .11, '#FFD9A0', .16], [.48, .88, .07, '#FFB04F', .18], [.7, .18, .08, '#4FC9C2', .1],
      [.06, .27, .1, '#FFE6C2', .1], [.95, .5, .06, '#FFB04F', .16], [.33, .72, .04, '#FFB04F', .4], [.55, .77, .035, '#FFD9A0', .35],
      [.9, .7, .04, '#FFB04F', .4], [.04, .72, .03, '#FFD9A0', .4]
    ];
    const BREATHE = [0, 2, 6, 12, 14, 15, 22];
    
    const root = document.querySelector('.fg');
    if (!root) return;
    const street = root.querySelector('.fg-street'), glass = root.querySelector('.fg-glass'), scene = root.querySelector('.fg-scene');
    const form = root.querySelector('.fg-form'), btn = root.querySelector('.fg-btn'), note = root.querySelector('.fg-note');
    const hint = root.querySelector('.fg-hint'), out = root.querySelector('.fg-out'), grain = root.querySelector('.fg-grain');
    const fields = [...form.querySelectorAll('.fg-field')];
    const calm = matchMedia('(prefers-reduced-motion: reduce)');
    const sx = street.getContext('2d'), g = glass.getContext('2d');
    g.imageSmoothingQuality = 'high';
    const MS = 2;
    const wait = ms => new Promise(r => setTimeout(r, ms));
    
    let seed = 20261015;
    const rnd = () => {
      seed = seed + 0x6D2B79F5 | 0;
      let t = Math.imul(seed ^ seed >>> 15, 1 | seed);
      t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
      return ((t ^ t >>> 14) >>> 0) / 4294967296;
    };
    const clamp = (v, a = 0, b = 1) => v < a ? a : v > b ? b : v;
    const smooth = t => (t = clamp(t), t * t * (3 - 2 * t));
    const rgb = h => [1, 3, 5].map(i => parseInt(h.slice(i, i + 2), 16));
    function bezier(x1, y1, x2, y2) {
      const cx = 3 * x1, bx = 3 * (x2 - x1) - cx, ax = 1 - cx - bx, cy = 3 * y1, by = 3 * (y2 - y1) - cy, ay = 1 - cy - by;
      return x => {
        if (x <= 0) return 0;
        if (x >= 1) return 1;
        let t = x;
        for (let i = 0; i < 8; i++) {
          const d = (3 * ax * t + 2 * bx) * t + cx;
          if (Math.abs(d) < 1e-6) break;
          t -= (((ax * t + bx) * t + cx) * t - x) / d;
        }
        return ((ay * t + by) * t + cy) * t;
      };
    }
    const easeOut = bezier(.23, 1, .32, 1);
    function canvas(w, h) {
      const cv = document.createElement('canvas');
      cv.width = Math.max(1, Math.ceil(w)); cv.height = Math.max(1, Math.ceil(h));
      const ctx = cv.getContext('2d');
      ctx.imageSmoothingQuality = 'high';
      return { cv, ctx, w: cv.width, h: cv.height };
    }
    function hash(a, b) {
      let n = Math.imul(a, 374761393) + Math.imul(b, 668265263) | 0;
      n = Math.imul(n ^ n >>> 13, 1274126177);
      return ((n ^ n >>> 16) >>> 0) / 4294967295;
    }
    function noise(x, y) {
      const xi = Math.floor(x), yi = Math.floor(y), u = smooth(x - xi), v = smooth(y - yi);
      return (hash(xi, yi) * (1 - u) + hash(xi + 1, yi) * u) * (1 - v) + (hash(xi, yi + 1) * (1 - u) + hash(xi + 1, yi + 1) * u) * v;
    }
    
    let W = 0, H = 0, DPR = 1, S = 1;
    let shot, fog, ghost, hole, rim, txt, holeImg, rimImg;
    let mw = 0, mh = 0, M = null, T = null, N = null;
    let drops = [], wiped = 0, holdUntil = 0, textHold = 0, fast = 0, fastT = 0, lastDown = -1e9;
    let state = 'idle', wave = null, write = null, formA = 1, formTo = 1, hintA = 1, outA = 0, ghostDirty = true;
    
    function disc(c, x, y, r, hex, a, haze = true) {
      const [R, G, B] = rgb(hex), k = q => `rgba(${R},${G},${B},${(a * q).toFixed(3)})`;
      const gr = c.createRadialGradient(x, y, 0, x, y, r);
      gr.addColorStop(0, k(.55)); gr.addColorStop(.72, k(.62)); gr.addColorStop(.9, k(1)); gr.addColorStop(.97, k(.5)); gr.addColorStop(1, k(0));
      c.fillStyle = gr; c.beginPath(); c.arc(x, y, r, 0, 7); c.fill();
      if (!haze) return;
      const hz = c.createRadialGradient(x, y, r * .6, x, y, r * 3.2);
      hz.addColorStop(0, k(.16)); hz.addColorStop(1, k(0));
      c.fillStyle = hz; c.beginPath(); c.arc(x, y, r * 3.2, 0, 7); c.fill();
    }
    function glow(c, x, y, r, color) {
      const gr = c.createRadialGradient(x, y, 0, x, y, r);
      gr.addColorStop(0, color); gr.addColorStop(1, 'rgba(0,0,0,0)');
      c.fillStyle = gr; c.fillRect(x - r, y - r, r * 2, r * 2);
    }
    function paintStreet(c, w, h) {
      const sky = c.createLinearGradient(0, 0, 0, h);
      sky.addColorStop(0, '#08111B'); sky.addColorStop(.42, '#0C1D29'); sky.addColorStop(.6, '#11313B'); sky.addColorStop(.74, '#1B1915'); sky.addColorStop(1, '#0C0A0A');
      c.globalCompositeOperation = 'source-over';
      c.fillStyle = sky; c.fillRect(0, 0, w, h);
      c.globalCompositeOperation = 'lighter';
      glow(c, .3 * w, .7 * h, .55 * Math.max(w, h), 'rgba(255,150,60,.16)');
      glow(c, .78 * w, .34 * h, .45 * Math.max(w, h), 'rgba(60,180,175,.10)');
      for (const [x, y, s, hex, a] of LIGHTS) {
        if (y < .58 || y > .66 || s > .03) continue;
        // wet asphalt under every street lamp
        c.save(); c.translate(x * w, y * h + .17 * h); c.scale(1, 6);
        const [R, G, B] = rgb(hex), r = s * S * 1.5, gr = c.createRadialGradient(0, 0, 0, 0, 0, r);
        gr.addColorStop(0, `rgba(${R},${G},${B},${(a * .13).toFixed(3)})`); gr.addColorStop(1, `rgba(${R},${G},${B},0)`);
        c.fillStyle = gr; c.fillRect(-r, -r, r * 2, r * 2); c.restore();
      }
      for (const [x, y, s, hex, a] of LIGHTS) disc(c, x * w, y * h, s * S, hex, a);
      c.globalCompositeOperation = 'source-over';
    }
    function buildFog() {
      // light through condensation: shrink the street a lot and grow it back in two soft steps
      const a = canvas(W / 4, H / 4), b = canvas(W / 12, H / 12), c = canvas(W / 30, H / 30), z = canvas(W / 70, H / 70), up = canvas(W / 10, H / 10), upz = canvas(W / 14, H / 14);
      a.ctx.drawImage(shot.cv, 0, 0, a.w, a.h); b.ctx.drawImage(a.cv, 0, 0, b.w, b.h); c.ctx.drawImage(b.cv, 0, 0, c.w, c.h); z.ctx.drawImage(c.cv, 0, 0, z.w, z.h);
      up.ctx.drawImage(c.cv, 0, 0, up.w, up.h); upz.ctx.drawImage(z.cv, 0, 0, upz.w, upz.h);
      const f = fog.ctx, fw = fog.w, fh = fog.h;
      f.setTransform(1, 0, 0, 1, 0, 0); f.globalCompositeOperation = 'source-over'; f.globalAlpha = 1;
      f.drawImage(up.cv, 0, 0, fw, fh);
      f.globalCompositeOperation = 'screen'; f.globalAlpha = .7; f.drawImage(upz.cv, 0, 0, fw, fh);
      f.globalCompositeOperation = 'source-over'; f.globalAlpha = 1;
      const veil = f.createLinearGradient(0, 0, 0, fh);
      veil.addColorStop(0, `rgba(168,184,197,${(.12 + .12 * FOG).toFixed(3)})`); veil.addColorStop(.6, `rgba(182,195,205,${(.15 + .13 * FOG).toFixed(3)})`); veil.addColorStop(1, `rgba(198,206,212,${(.2 + .14 * FOG).toFixed(3)})`);
      f.fillStyle = veil; f.fillRect(0, 0, fw, fh);
      // condensation is thousands of tiny beads, each dark at the rim and lit on top
      f.setTransform(DPR, 0, 0, DPR, 0, 0);
      const dark = new Path2D(), lit = new Path2D(), n = Math.round(W * H / 55);
      for (let i = 0; i < n; i++) {
        const x = rnd() * W, y = rnd() * H, r = rnd() < .03 ? 1.5 + rnd() * 1.6 : .45 + rnd() ** 3 * 1.3;
        dark.moveTo(x + r * .3 + r * .7, y + r * .3); dark.arc(x + r * .3, y + r * .3, r * .7, 0, 7);
        lit.moveTo(x - r * .3 + r * .4, y - r * .35); lit.arc(x - r * .3, y - r * .35, r * .4, 0, 7);
      }
      f.fillStyle = `rgba(20,30,40,${(.22 * FOG).toFixed(3)})`; f.fill(dark);
      f.globalCompositeOperation = 'screen'; f.fillStyle = `rgba(255,255,255,${(.5 * FOG).toFixed(3)})`; f.fill(lit); f.globalCompositeOperation = 'source-over';
    }
    function sizeMask() {
      const ow = mw, oh = mh, oM = M, oT = T;
      mw = Math.ceil(W / MS) + 1; mh = Math.ceil(H / MS) + 1;
      M = new Float32Array(mw * mh); T = new Float32Array(mw * mh); N = new Float32Array(mw * mh);
      for (let y = 0; y < mh; y++) for (let x = 0; x < mw; x++) {
        const i = y * mw + x;
        // the glass fogs up in patches, never all at once
        N[i] = .7 + .6 * noise(x * MS / 170, y * MS / 170);
        if (oM) { const j = Math.min(oh - 1, y * oh / mh | 0) * ow + Math.min(ow - 1, x * ow / mw | 0); M[i] = oM[j]; T[i] = oT[j]; }
      }
      hole = canvas(mw, mh); rim = canvas(mw, mh); txt = canvas(mw, mh);
      holeImg = hole.ctx.createImageData(mw, mh); rimImg = rim.ctx.createImageData(mw, mh);
      for (let i = 0; i < mw * mh; i++) { rimImg.data[i * 4] = 214; rimImg.data[i * 4 + 1] = 226; rimImg.data[i * 4 + 2] = 234; }
    }
    function setup() {
      const w = root.clientWidth, h = root.clientHeight;
      if (!w || !h || (w === W && h === H)) return;
      W = w; H = h; DPR = Math.min(2, window.devicePixelRatio || 1); S = Math.max(420, Math.min(W, H));
      for (const cv of [street, glass]) { cv.width = Math.round(W * DPR); cv.height = Math.round(H * DPR); }
      shot = canvas(W * DPR, H * DPR); shot.ctx.setTransform(DPR, 0, 0, DPR, 0, 0); paintStreet(shot.ctx, W, H);
      fog = canvas(W * DPR, H * DPR); buildFog();
      ghost = canvas(W / 18, H / 18);
      sizeMask();
      sx.setTransform(1, 0, 0, 1, 0, 0); sx.drawImage(shot.cv, 0, 0);
      if (!drops.length && state === 'idle') bead();
      ghostDirty = true;
    }
    // water that was already on the glass: a few beads, more of them low down
    function bead() {
      for (let i = 0; i < 34; i++) {
        const y = H * (.55 + .45 * Math.sqrt(rnd())), r = .7 + rnd() ** 2 * 3.4;
        drops.push(drop(rnd() * W, y, r * r));
      }
    }
    function drop(x, y, vol, ink = false) {
      return { x, y, vol, r: Math.sqrt(vol), th: 3.4 + rnd() * 1.5, run: false, vy: 0, ph: rnd() * 6.3, sway: 1.5 + rnd() * 4, trav: 0, next: 10 + rnd() * 18, pause: 0, ink, fade: false };
    }
    
    function stamp(A, x, y, r, k) {
      const cx = x / MS, cy = y / MS, cr = r / MS, inner = cr * .5;
      const x0 = Math.max(0, Math.floor(cx - cr)), x1 = Math.min(mw - 1, Math.ceil(cx + cr)), y0 = Math.max(0, Math.floor(cy - cr)), y1 = Math.min(mh - 1, Math.ceil(cy + cr));
      for (let j = y0; j <= y1; j++) for (let i = x0; i <= x1; i++) {
        const d = Math.hypot(i - cx, j - cy);
        if (d >= cr) continue;
        const f = d <= inner ? 1 : 1 - smooth((d - inner) / (cr - inner)), n = j * mw + i;
        A[n] = 1 - (1 - A[n]) * (1 - f * k);
      }
    }
    function breathe(x, y, r, k) {
      const cx = x / MS, cy = y / MS, cr = r / MS;
      for (let j = Math.max(0, cy - cr | 0); j <= Math.min(mh - 1, cy + cr); j++) for (let i = Math.max(0, cx - cr | 0); i <= Math.min(mw - 1, cx + cr); i++) {
        const d = Math.hypot(i - cx, j - cy);
        if (d < cr) M[j * mw + i] *= 1 - (1 - smooth(d / cr)) * k;
      }
    }
    const clearAt = (x, y) => { const i = clamp(y / MS | 0, 0, mh - 1) * mw + clamp(x / MS | 0, 0, mw - 1); return Math.max(M[i], T[i]); };
    
    // the cloth pushes the water it meets to the edge of the strip
    function push(x, y, r, nx, ny, step) {
      for (const d of drops) {
        if (d.run || d.fade) continue;
        const dx = d.x - x, dy = d.y - y, dist = Math.hypot(dx, dy);
        if (dist >= r * .9) continue;
        const ux = dist > 1 ? dx / dist : nx, uy = dist > 1 ? dy / dist : ny;
        d.x = x + ux * r * .95; d.y = y + uy * r * .95; d.vol += .22;
      }
      for (const side of [-1, 1]) {
        // water is never laid in a neat row: skip some spots, scatter the rest
        if (rnd() < .45) continue;
        const ex = x + nx * side * r * (.86 + rnd() * .2) + (rnd() - .5) * 14, ey = y + ny * side * r * (.86 + rnd() * .2) + (rnd() - .5) * 14;
        if (clearAt(ex, ey) < .6) deposit(ex, ey, step * .3);
      }
    }
    function deposit(x, y, v) {
      let best = null, bd = 1e9;
      for (const d of drops) {
        if (d.run) continue;
        const dist = Math.hypot(d.x - x, d.y - y);
        if (dist < d.r + 5 && dist < bd) { best = d; bd = dist; }
      }
      if (best) best.vol += v;
      else if (drops.length < DROP_COUNT) drops.push(drop(x + (rnd() - .5) * 3, y + (rnd() - .5) * 3, v + .25));
    }
    
    const last = new Map();
    function rub(id, cx, cy, e) {
      if (!M) return;
      const b = root.getBoundingClientRect(), x = cx - b.left, y = cy - b.top;
      const pressed = e.pointerType !== 'mouse' || (e.buttons & 1);
      const r = e.pointerType === 'touch' ? BRUSH * 1.2 : pressed ? BRUSH * 1.9 : BRUSH;
      const p = last.get(id);
      last.set(id, { x, y, run: p ? p.run : rnd() * 99 });
      if (!p) return stamp(M, x, y, r, .5);
      const dx = x - p.x, dy = y - p.y, len = Math.hypot(dx, dy);
      if (len < .5) return;
      const step = Math.max(2, r * .22), nx = -dy / len, ny = dx / len;
      for (let s = Math.min(step, len); s <= len + .01; s += step) {
        const px = p.x + dx * s / len, py = p.y + dy * s / len, run = p.run + s;
        // a hand never wipes a perfect tube: the width breathes along the stroke
        const rr = r * (.76 + .48 * noise(run * .025, id * 3.1)), jx = (noise(run * .2, 7) - .5) * r * .12, jy = (noise(run * .2, 19) - .5) * r * .12;
        stamp(M, px + jx, py + jy, rr, .5);
        push(px, py, rr, nx, ny, step * r / BRUSH);
      }
      last.get(id).run = p.run + len;
      wiped += len;
    }
    root.addEventListener('pointermove', e => {
      const list = e.getCoalescedEvents ? e.getCoalescedEvents() : [];
      for (const ev of list.length ? list : [e]) rub(e.pointerId, ev.clientX, ev.clientY, e);
    });
    root.addEventListener('pointerdown', e => { lastDown = performance.now(); last.delete(e.pointerId); rub(e.pointerId, e.clientX, e.clientY, e); });
    for (const type of ['pointerup', 'pointercancel', 'pointerleave']) root.addEventListener(type, e => { if (type !== 'pointerup' || e.pointerType !== 'mouse') last.delete(e.pointerId); });
    
    function stepDrops(dt) {
      const still = calm.matches;
      for (let i = 0; i < drops.length; i++) {
        const a = drops[i];
        if (a.run || a.fade) continue;
        for (let j = i + 1; j < drops.length; j++) {
          const b = drops[j];
          if (b.run || b.fade || Math.hypot(a.x - b.x, a.y - b.y) > (a.r + b.r) * .8) continue;
          const big = a.vol >= b.vol ? a : b, small = big === a ? b : a, k = small.vol / (a.vol + b.vol);
          big.x += (small.x - big.x) * k; big.y += (small.y - big.y) * k; big.vol += small.vol; small.vol = 0;
        }
      }
      for (const d of drops) {
        if (d.fade) { d.vol *= .8; d.r = Math.sqrt(d.vol); continue; }
        d.r = Math.sqrt(d.vol);
        if (!d.run && d.r > d.th && !still) d.run = true;
        if (!d.run) continue;
        if (d.pause > 0) { d.pause -= dt; continue; }
        const ox = d.x, oy = d.y;
        const pull = 520 * DROP_FALL * (.6 + d.r / 10);
        d.vy += (pull - 3.2 * d.vy) * dt;
        d.y += d.vy * dt;
        d.x += Math.cos(d.y * .05 + d.ph) * .05 * d.sway * (d.y - oy);
        const len = Math.hypot(d.x - ox, d.y - oy), A = d.ink ? T : M;
        for (let s = 0; s <= len; s += 2) stamp(A, ox + (d.x - ox) * s / (len || 1), oy + (d.y - oy) * s / (len || 1), d.r * 1.15, .8);
        for (const o of drops) {
          if (o === d || o.vol === 0 || Math.hypot(o.x - d.x, o.y - d.y) > (o.r + d.r) * .85) continue;
          d.vol += o.vol; o.vol = 0;
        }
        d.trav += len; d.vol = Math.max(0, d.vol - dt * .5);
        if (d.trav > d.next) {
          // a drop leaves a little water behind and sometimes catches for a moment
          drops.push(drop(d.x + (rnd() - .5) * 2, d.y - d.r * 1.3, .25 + rnd() * .5, d.ink));
          d.vol = Math.max(0, d.vol - .4); d.next = d.trav + 12 + rnd() * 22;
          if (rnd() < .22 && d.r < d.th * 1.25) { d.pause = .06 + rnd() * .18; d.vy *= .2; }
        }
        if (Math.sqrt(d.vol) < d.th * .62) { d.run = false; d.vy = 0; }
      }
      drops = drops.filter(d => d.vol > .12 && d.y < H + 30 && !(d.fade && d.vol < .2));
    }
    
    // one pass over the glass: the fog creeps back, then the mask becomes the holes and the wet rim around them
    function glassPass(dt, now) {
      let rm = 0, rt = 0;
      if (!calm.matches || fast) {
        rm = fast ? dt / fast : FOG_BACK > 0 && now > holdUntil ? dt / FOG_BACK : 0;
        rt = fastT ? dt / fastT : FOG_BACK > 0 && now > textHold ? dt / FOG_BACK : 0;
      }
      const hd = holeImg.data, rd = rimImg.data;
      for (let i = 0, n = mw * mh; i < n; i++) {
        let m = M[i], t = T[i];
        if (m > 0 && rm) M[i] = m = Math.max(0, m - rm * N[i]);
        if (t > 0 && rt) T[i] = t = Math.max(0, t - rt * N[i]);
        if (t > m) m = t;
        if (m <= .06) { hd[i * 4 + 3] = 0; rd[i * 4 + 3] = 0; continue; }
        let a = (m - .06) / .56;
        a = a >= 1 ? 1 : a * a * (3 - 2 * a);
        hd[i * 4 + 3] = a * 255;
        rd[i * 4 + 3] = a * (1 - a) * 150;
      }
      hole.ctx.putImageData(holeImg, 0, 0); rim.ctx.putImageData(rimImg, 0, 0);
    }
    
    function box(el) {
      const b = root.getBoundingClientRect(), r = el.getBoundingClientRect();
      return [r.left - b.left, r.top - b.top, r.width, r.height];
    }
    function paintGhost() {
      const c = ghost.ctx;
      c.setTransform(1, 0, 0, 1, 0, 0); c.clearRect(0, 0, ghost.w, ghost.h); c.setTransform(ghost.w / W, 0, 0, ghost.h / H, 0, 0);
      c.fillStyle = 'rgba(235,240,245,.5)';
      for (const el of form.querySelectorAll('.fg-title, .fg-top')) { const [x, y, w, h] = box(el); c.fillRect(x, y + h * .25, w, h * .5); }
      for (const f of fields) {
        const [x, y, w, h] = box(f);
        c.fillStyle = 'rgba(220,230,238,.45)'; c.fillRect(x, y + h - 2, w, 2);
        if (f.value) { c.fillStyle = 'rgba(240,244,248,.7)'; c.fillRect(x, y + h * .35, Math.min(w, f.value.length * 10), h * .3); }
      }
      const [x, y, w, h] = box(btn);
      // through the fog the button is its line of light and a warm glow
      c.fillStyle = 'rgba(255,236,210,.95)'; c.fillRect(x, y + h - 3, w, 3);
      c.fillStyle = 'rgba(255,214,170,.35)'; c.fillRect(x, y + h - 14, w, 22);
      c.fillStyle = 'rgba(250,244,236,.75)'; c.fillRect(x, y + h * .3, 70, h * .4); c.fillRect(x + w - 24, y + h * .35, 22, h * .3);
      ghostDirty = false;
    }
    
    function compose(now) {
      if (!calm.matches) {
        sx.setTransform(1, 0, 0, 1, 0, 0); sx.globalCompositeOperation = 'source-over'; sx.drawImage(shot.cv, 0, 0);
        sx.setTransform(DPR, 0, 0, DPR, 0, 0); sx.globalCompositeOperation = 'lighter';
        for (const i of BREATHE) {
          const [x, y, s, hex, a] = LIGHTS[i], k = .5 + .5 * Math.sin(now / 1000 * (.9 + i * .07) + i);
          disc(sx, x * W, y * H, s * S, hex, a * .14 * k, false);
        }
        sx.globalCompositeOperation = 'source-over';
      }
      g.setTransform(1, 0, 0, 1, 0, 0); g.globalCompositeOperation = 'source-over'; g.globalAlpha = 1;
      g.clearRect(0, 0, glass.width, glass.height);
      g.globalAlpha = .35 + .65 * FOG; g.drawImage(fog.cv, 0, 0);
      g.setTransform(DPR, 0, 0, DPR, 0, 0);
      if (formA > .01) { g.globalCompositeOperation = 'screen'; g.globalAlpha = .6 * formA; g.drawImage(ghost.cv, 0, 0, W, H); }
      g.globalAlpha = 1;
      g.globalCompositeOperation = 'destination-out'; g.drawImage(hole.cv, 0, 0, mw * MS, mh * MS);
      g.globalCompositeOperation = 'source-over'; g.drawImage(rim.cv, 0, 0, mw * MS, mh * MS);
      for (const d of drops) {
        const r = d.r;
        if (r < .4) continue;
        if (r < 2.2) {
          // a bead: clear in the middle, a darker lower rim and one bright point of light
          g.fillStyle = 'rgba(225,235,242,.2)'; g.beginPath(); g.arc(d.x, d.y, r + .4, 0, 7); g.fill();
          g.fillStyle = 'rgba(6,12,18,.26)'; g.beginPath(); g.arc(d.x + r * .12, d.y + r * .18, r * .78, 0, 7); g.fill();
          g.fillStyle = 'rgba(255,255,255,.9)'; g.beginPath(); g.arc(d.x - r * .32, d.y - r * .36, Math.max(.45, r * .34), 0, 7); g.fill();
          continue;
        }
        const ex = d.run ? r * .88 : r, ey = d.run ? r * 1.16 : r, v = r * 12;
        // a drop is a small lens: it shows a wide piece of the street, upside down
        g.save(); g.beginPath(); g.ellipse(d.x, d.y, ex, ey, 0, 0, 7); g.clip();
        g.translate(d.x, d.y); g.scale(-1, -1);
        g.drawImage(street, (d.x - v / 2) * DPR, (d.y - v / 2) * DPR, v * DPR, v * DPR, -ex, -ey, ex * 2, ey * 2);
        g.restore();
        const sh = g.createRadialGradient(d.x, d.y - r * .2, r * .2, d.x, d.y, r * 1.05);
        sh.addColorStop(0, 'rgba(255,255,255,.06)'); sh.addColorStop(.7, 'rgba(0,0,0,.08)'); sh.addColorStop(1, 'rgba(0,0,0,.42)');
        g.fillStyle = sh; g.beginPath(); g.ellipse(d.x, d.y, ex, ey, 0, 0, 7); g.fill();
        g.fillStyle = 'rgba(255,255,255,.75)'; g.beginPath(); g.ellipse(d.x - r * .32, d.y - ey * .42, r * .24, r * .16, -.5, 0, 7); g.fill();
        g.fillStyle = 'rgba(255,240,215,.32)'; g.beginPath(); g.ellipse(d.x + r * .08, d.y + ey * .62, r * .55, r * .2, 0, 0, 7); g.fill();
      }
    }
    
    // after Log in: the glass clears from the button outward, fogs up again and the words appear in it
    function startWave(now) {
      const [x, y, w, h] = box(btn), far = Math.max(Math.hypot(x, y), Math.hypot(W - x, y), Math.hypot(x, H - y), Math.hypot(W - x, H - y));
      wave = { x: x + w / 2, y: y + h / 2, t0: now, R: far + 120 };
      const [fx, fy, fw, fh] = box(form);
      write = { cx: fx + fw / 2, cy: fy + fh * .42 };
    }
    function stepWave(now) {
      const u = (now - wave.t0) / 760, R = easeOut(u) * wave.R, edge = 70;
      for (let j = 0; j < mh; j++) for (let i = 0; i < mw; i++) {
        const d = Math.hypot(i * MS - wave.x, j * MS - wave.y);
        if (d >= R) continue;
        const n = j * mw + i, f = smooth((R - d) / edge);
        if (f > M[n]) M[n] = f;
      }
      for (const d of drops) if (Math.hypot(d.x - wave.x, d.y - wave.y) < R) d.fade = true;
      if (u >= 1) { wave = null; state = 'hold'; holdUntil = now + 450; }
    }
    function prepareWords() {
      const c = txt.ctx, fs = clamp(W * .085, 46, 104), font = `700 ${fs}px "Bradley Hand", "Segoe Print", "Noteworthy", cursive`;
      c.setTransform(1, 0, 0, 1, 0, 0); c.clearRect(0, 0, mw, mh);
      c.font = font;
      const one = c.measureText(WRITE).width;
      const parts = one > W * .86 && WRITE.includes(' ') ? [WRITE.slice(0, WRITE.lastIndexOf(' ')), WRITE.slice(WRITE.lastIndexOf(' ') + 1)] : [WRITE];
      const widths = parts.map(p => c.measureText(p).width), total = widths.reduce((s, w) => s + w, 0), lh = fs * 1.08, tilt = -.05;
      c.setTransform(1 / MS, 0, 0, 1 / MS, 0, 0);
      c.translate(write.cx, write.cy); c.rotate(tilt);
      c.font = font; c.textBaseline = 'middle'; c.lineJoin = c.lineCap = 'round'; c.lineWidth = fs * .075; c.fillStyle = c.strokeStyle = '#fff';
      parts.forEach((p, k) => { const y = (k - (parts.length - 1) / 2) * lh; c.fillText(p, -widths[k] / 2, y); c.strokeText(p, -widths[k] / 2, y); });
      const a = c.getImageData(0, 0, mw, mh).data, cells = [], ord = [], val = [], tips = [];
      const cos = Math.cos(-tilt), sin = Math.sin(-tilt), top = -(parts.length * lh) / 2;
      let before = 0;
      const startOf = parts.map((_, k) => { const s = before; before += widths[k]; return s; });
      for (let j = 0; j < mh; j++) for (let i = 0; i < mw; i++) {
        const n = j * mw + i, v = a[n * 4 + 3] / 255;
        if (v < .04) continue;
        const px = i * MS - write.cx, py = j * MS - write.cy, ux = px * cos - py * sin, uy = px * sin + py * cos;
        const k = clamp(Math.floor((uy - top) / lh), 0, parts.length - 1);
        const o = (startOf[k] + ux + widths[k] / 2) / total;
        cells.push(n); ord.push(o); val.push(v);
        if (v > .6 && j + 2 < mh && a[(n + 2 * mw) * 4 + 3] < 26) tips.push([i * MS, j * MS + MS, o]);
      }
      tips.sort((p, q) => p[2] - q[2]);
      const drips = [];
      for (let k = 0; k < 7 && tips.length; k++) { const t = tips[Math.min(tips.length - 1, Math.floor((k + .3 + rnd() * .4) / 7 * tips.length))]; drips.push({ x: t[0], y: t[1], o: t[2] + .04 + rnd() * .1, done: false }); }
      Object.assign(write, { cells, ord, val, drips });
    }
    function stepWrite(now) {
      const p = (now - write.t0) / 1300, soft = .035;
      const { cells, ord, val } = write;
      for (let k = 0; k < cells.length; k++) {
        const f = clamp((p - ord[k]) / soft) * val[k], n = cells[k];
        if (f > T[n]) T[n] = f;
      }
      for (const d of write.drips) {
        if (d.done || p < d.o || calm.matches) continue;
        d.done = true;
        const w = drop(d.x, d.y, 0, true);
        w.vol = (w.th + 1.1) ** 2;
        drops.push(w);
      }
      if (p >= 1.25) { state = 'done'; textHold = now + 1500; out.hidden = false; }
    }
    
    function frame(now) {
      const dt = Math.min(.05, frame.t ? (now - frame.t) / 1000 : .016);
      frame.t = now;
      if (W && M) {
        if (wave) stepWave(now);
        if (state === 'hold' && now >= holdUntil) {
          state = 'fogin'; fast = .9; formTo = 0; scene.inert = true;
          setTimeout(() => { fast = 0; }, 900);
          write.t0 = now + 220; prepareWords();
        }
        if ((state === 'fogin' || state === 'write') && now >= write.t0) { state = 'write'; stepWrite(now); }
        stepDrops(dt);
        glassPass(dt, now);
        const k = 1 - Math.exp(-dt * 9);
        formA += (formTo - formA) * k; scene.style.opacity = formA.toFixed(3);
        hintA += ((wiped > 260 || state !== 'idle' ? 0 : 1) - hintA) * k; hint.style.opacity = hintA.toFixed(3);
        outA += ((state === 'done' ? 1 : 0) - outA) * k; out.style.opacity = outA.toFixed(3);
        if (ghostDirty) paintGhost();
        compose(now);
      }
      requestAnimationFrame(frame);
    }
    
    function bad(field, text) {
      note.textContent = text;
      field.setAttribute('aria-invalid', 'true');
      field.focus();
      const [x, y, w, h] = box(note);
      for (let s = 0; s <= w; s += 10) stamp(M, x + s, y + h / 2, 26, .6);
    }
    async function checkLogin(email, pass) {
      // a real server request goes here, for example:
      // const res = await fetch('/api/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email, password: pass }) });
      // return res.ok;
      await wait(600);
      return email.length > 0 && pass.length > 0;
    }
    form.addEventListener('submit', async e => {
      e.preventDefault();
      if (state !== 'idle') return;
      const email = fields[0].value.trim(), pass = fields[1].value;
      fields.forEach(f => f.removeAttribute('aria-invalid'));
      if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) return bad(fields[0], 'Enter your email, like name@example.com.');
      if (pass.length < 6) return bad(fields[1], 'The password needs at least 6 characters.');
      note.textContent = '';
      const label = btn.querySelector('span');
      state = 'busy'; btn.disabled = true; label.textContent = 'Logging in';
      const ok = await checkLogin(email, pass);
      btn.disabled = false; label.textContent = 'Log in';
      if (!ok) { state = 'idle'; return bad(fields[1], 'That email and password do not match.'); }
      fields.forEach(f => f.blur());
      const now = performance.now();
      holdUntil = 0;
      if (calm.matches) {
        M.fill(0); state = 'fogin'; formTo = 0; scene.inert = true;
        const [fx, fy, fw, fh] = box(form);
        write = { cx: fx + fw / 2, cy: fy + fh * .42, t0: now - 2000 };
        prepareWords(); stepWrite(now);
        return;
      }
      state = 'wave'; startWave(now);
    });
    for (const f of fields) {
      f.addEventListener('focus', () => {
        holdUntil = performance.now() + 6000;
        // reached with Tab: wipe a little window for it, the way a hand would
        if (performance.now() - lastDown > 400) { const [x, y, w, h] = box(f); for (let s = 0; s <= w; s += 14) stamp(M, x + s, y + h / 2, h * .9, .55); }
      });
      f.addEventListener('input', () => {
        holdUntil = performance.now() + 6000;
        f.removeAttribute('aria-invalid'); ghostDirty = true;
        // typing up close: a little breath fogs the glass just under the field
        if (!calm.matches) {
          const [x, y, w, h] = box(f), m = measure.measureText(f.type === 'password' ? '•'.repeat(f.value.length) : f.value).width;
          breathe(x + Math.min(w, m), y + h + 6, 26, .22);
        }
      });
    }
    const measure = document.createElement('canvas').getContext('2d');
    measure.font = '18px system-ui, sans-serif';
    // the light on the line stands where the caret is
    function light(f) {
      const upto = f.value.slice(0, f.selectionStart ?? f.value.length), shown = f.type === 'password' ? '•'.repeat(upto.length) : upto;
      f.parentNode.style.setProperty('--x', Math.min(f.clientWidth - 8, measure.measureText(shown).width + 2) + 'px');
    }
    for (const f of fields) for (const type of ['focus', 'input', 'keyup', 'click', 'select']) f.addEventListener(type, () => light(f));
    out.addEventListener('click', () => {
      state = 'idle'; formTo = 1; scene.inert = false; out.hidden = true; outA = 0;
      fields.forEach(f => { f.value = ''; }); note.textContent = '';
      fastT = .6; setTimeout(() => { fastT = 0; }, 600);
      ghostDirty = true; fields[0].focus();
    });
    
    const tile = canvas(140, 140), px = tile.ctx.createImageData(140, 140);
    for (let i = 0; i < px.data.length; i += 4) { const v = rnd() * 255; px.data[i] = px.data[i + 1] = px.data[i + 2] = v; px.data[i + 3] = 22; }
    tile.ctx.putImageData(px, 0, 0);
    grain.style.backgroundImage = `url(${tile.cv.toDataURL()})`;
    
    new ResizeObserver(() => setup()).observe(root);
    setup();
    requestAnimationFrame(frame);
    })();

Подключение к серверу

Форма ничего не отправляет, пока вы её не подключите. Найдите a real server request goes here и поставьте туда свой fetch().

Полезно знать

Tilda, Webflow, WordPress

Нажмите «Скопировать весь код» вверху и вставьте его в один HTML-блок.

Tilda

Добавить блок, Другое, T123 HTML-код. Вставьте и сохраните. Проверяйте на опубликованной странице, в редакторе скрипты не запускаются.

Webflow

Панель Add, Embed. Вставьте и нажмите Save & Close. Свой код работает на опубликованном сайте.

WordPress

Добавить блок, Произвольный HTML. Вставьте и нажмите «Обновить».

Ещё в разделе «Вход и формы»

Все
Скопировано