Вход со светлячком

Светлячок освещает тёмную форму входа. Он садится на поле, в котором вы печатаете, ныряет в пароль и подсвечивает каждый символ, касается глазка и заливает кнопку светом, когда вы входите.

Нажмите на поле почты и печатайте, потом на пароль, потом нажмите Sign in.

Скачать

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

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

STIFF0.04

Как сильно светлячок тянется к цели. Больше значит быстрее.

DAMP0.76

Как быстро он успокаивается. Ближе к 1 значит больше пружинит.

190px.night

Размер освещённого круга вокруг светлячка.

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

Страницы входа и регистрации, форма листа ожидания, любой тёмный лендинг с формой.

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

  1. CSS

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

    /* the dark around the form, the firefly carries the light */
    .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, 50%), rgba(7,6,10,0) 0, rgba(7,6,10,.42) 95px, rgba(7,6,10,.78) 190px); }
    .night.day { opacity: .35; }
    
    .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: #16141A; overflow: hidden;
      box-shadow: inset 0 0 0 1.2px rgba(255,238,215,.11); transition: box-shadow .3s cubic-bezier(.23, 1, .32, 1); }
    .field:focus-within, .field.lit { box-shadow: inset 0 0 0 1.6px rgba(255,190,95,.9), 0 0 0 4px rgba(255,181,71,.16); }
    /* light under the surface while the firefly is inside the field */
    .field::before { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .2s ease;
      background: radial-gradient(90px 46px at var(--gx, -100px) 50%, rgba(255,190,100,.4), rgba(255,150,60,.1) 50%, transparent 75%); }
    .field.inside::before { opacity: 1; }
    .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: #F4EFE6; caret-color: #FFB547; }
    .field input::placeholder { color: rgba(205,195,180,.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: #F4EFE6; }
    .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: flash .5s cubic-bezier(.23, 1, .32, 1); }
    @keyframes flash { from { filter: drop-shadow(0 0 5px #FFC46E) brightness(1.7); } }
    .caret { position: absolute; left: 0; top: 16px; width: 2px; height: 20px; background: #FFB547; 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(235,228,215,.55); transition: color .2s ease, transform .16s ease-out; }
    .eye:active { transform: scale(.94); }
    .eye:focus-visible { outline: 2px solid #FFB547; 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: #FFBE5F; }
    .show .eye .slash { stroke-dashoffset: 26; }
    
    /* the button fills with light from the point where the firefly dove in */
    .send { position: relative; height: 54px; border: 0; border-radius: 27px; background: #211D24; box-shadow: inset 0 0 0 1.2px rgba(255,238,215,.10);
      color: #EFE8DC; 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 #FFB547; outline-offset: 3px; }
    .send::before { content: ""; position: absolute; inset: 0; background: linear-gradient(#FFC874, #FFA53A);
      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 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: #231505; 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: #2A252E; }
    }
    
    /* the firefly */
    .spark { position: fixed; left: 0; top: 0; z-index: 6; width: 120px; height: 120px; margin: -60px 0 0 -60px; pointer-events: none; transition: opacity .15s ease; }
    .spark.inside { opacity: 0; }
    .spark i { position: absolute; left: 50%; top: 50%; }
    .spark .glow { left: 0; top: 0; width: 100%; height: 100%; border-radius: 50%; animation: pulse 1.2s ease-in-out infinite alternate;
      background: radial-gradient(circle at 50% 56%, rgba(255,196,110,.6), rgba(255,160,60,.2) 22%, rgba(255,150,50,0) 58%); }
    @keyframes pulse { to { opacity: .8; } }
    .spark .wing { width: 22px; height: 10px; margin-top: -17px; border-radius: 50%; animation: .07s ease-in-out infinite alternate; }
    .spark .wing.l { margin-left: -22px; transform-origin: 100% 60%; background: linear-gradient(270deg, rgba(255,246,230,.45), rgba(255,246,230,.08)); animation-name: flap-l; }
    .spark .wing.r { margin-left: 0; transform-origin: 0 60%; background: linear-gradient(90deg, rgba(255,246,230,.45), rgba(255,246,230,.08)); animation-name: flap-r; }
    @keyframes flap-l { from { rotate: 8deg; } to { rotate: 38deg; } }
    @keyframes flap-r { from { rotate: -8deg; } to { rotate: -38deg; } }
    .spark .head { width: 7px; height: 10px; margin: -15px 0 0 -3.5px; border-radius: 50%; background: #2B2016; }
    .spark .body { width: 22px; height: 24px; margin: -6px 0 0 -11px; border-radius: 50%;
      background: radial-gradient(circle at 50% 45%, #FFFCEE, rgba(255,216,135,.95) 40%, rgba(255,170,70,0) 72%); }
    .ember { position: fixed; z-index: 6; width: 9px; height: 9px; border-radius: 50%; pointer-events: none;
      background: radial-gradient(circle, #FFECBE, rgba(255,180,80,.5) 35%, transparent 70%); }
    
    @media (prefers-reduced-motion: reduce) {
      .spark .wing, .spark .glow, .dots i.new, .text b.new { animation: none; }
      .send span { transform: none !important; }
    }
  2. HTML

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

    <div class="night" aria-hidden="true"></div>
    
    <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>
      <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>
    
    <div class="spark" aria-hidden="true"><i class="glow"></i><i class="wing l"></i><i class="wing r"></i><i class="head"></i><i class="body"></i></div>
  3. JavaScript

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

    // how hard the firefly pulls toward its goal, and how fast it calms down
    const STIFF = 0.04, DAMP = 0.76;
    
    const $ = s => document.querySelector(s);
    const form = $('.login'), email = $('#email'), pass = $('#pass'), eye = $('.eye'), send = $('.send');
    const mailField = email.parentElement, passField = pass.parentElement;
    const spark = $('.spark'), night = $('.night'), dots = $('.dots'), text = $('.text'), caret = $('.caret');
    const reduce = matchMedia('(prefers-reduced-motion: reduce)').matches;
    const wait = ms => new Promise(r => setTimeout(r, ms));
    const pen = document.createElement('canvas').getContext('2d');
    pen.font = '500 16px system-ui, sans-serif';
    
    // where the firefly goes for each element: it lands on top of a field, into the middle of a button
    function at(el) {
      const r = el.getBoundingClientRect();
      if (el === email || el === pass) return { x: r.left + 22, y: r.top - 4 };
      return { x: r.left + r.width / 2, y: r.top + r.height / 2 };
    }
    // while you type it follows the last character
    function caretGoal(input) {
      const r = input.getBoundingClientRect(), v = input.value;
      if (input === email) return { x: r.left + 24 + Math.min(pen.measureText(v).width, r.width - 70), y: r.top - 4 };
      const w = 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 };
    }
    
    let x = -60, y = innerHeight / 2, vx = 0, vy = 0;
    let goal = { x, y }, dive = null;
    let last = performance.now(), acc = 0;
    
    (function fly(now = performance.now()) {
      const box = dive && dive.getBoundingClientRect();
      acc += Math.min(100, now - last); last = now;
      for (; acc >= 1000 / 60; acc -= 1000 / 60) {            // 60 steps a second on any screen
        vx = (vx + (goal.x - x) * STIFF) * DAMP;
        vy = (vy + (goal.y - y) * STIFF) * DAMP;
        x += vx; y += vy;
      }
      spark.style.translate = `${x}px ${y}px`;
      night.style.setProperty('--x', x + 'px');
      night.style.setProperty('--y', y + 'px');
      const inside = !!box && x > box.left && x < box.right && y > box.top && y < box.bottom;
      spark.classList.toggle('inside', inside);
      if (dive === passField) {
        passField.classList.toggle('inside', inside);
        if (inside) passField.style.setProperty('--gx', x - box.left + 'px');
      }
      requestAnimationFrame(fly);
    })();
    
    for (const el of [email, pass, eye, send])
      el.onfocus = el.onclick = () => goal = at(el);
    
    email.addEventListener('input', () => { goal = caretGoal(email); });
    
    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) => mark(document.createElement('i'), i)));
      text.replaceChildren(...v.map((ch, i) => { const b = mark(document.createElement('b'), i); b.textContent = ch; return b; }));
      caret.style.translate = (passField.classList.contains('show') ? text.offsetWidth : v.length * 14) + 'px 0';
    }
    function diveIntoPassword() {
      if (!pass.value) { dive = null; passField.classList.remove('inside'); goal = at(pass); return; }
      dive = passField; goal = caretGoal(pass);
    }
    pass.addEventListener('input', () => { paintPassword(true); diveIntoPassword(); });
    pass.addEventListener('focus', diveIntoPassword);
    pass.addEventListener('blur', () => { if (dive === passField) { dive = null; passField.classList.remove('inside'); } });
    
    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);
    });
    
    // Put your real request here. Return true when the server accepts the login.
    async function signIn(login, password) {
      await wait(250);
      return true;
      // const res = await fetch('/api/login', {
      //   method: 'POST',
      //   headers: { 'Content-Type': 'application/json' },
      //   body: JSON.stringify({ login, password }),
      // });
      // return res.ok;
    }
    
    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 = at(empty); empty.focus(); return; }
      dive = send; goal = at(send);
      const [ok] = await Promise.all([signIn(email.value, pass.value), wait(300)]);
      if (!ok) { dive = null; goal = at(pass); pass.focus(); return; }
      send.style.setProperty('--hx', x - send.getBoundingClientRect().left + 'px');
      send.classList.add('done');
      night.classList.add('day');
      if (!reduce) burst(send);
      await wait(750);
      dive = null;
      const r = send.getBoundingClientRect();
      goal = { x: r.left + r.width * .62, y: r.top - 8 };
    });
    
    function burst(el) {
      const r = el.getBoundingClientRect();
      for (let i = 0; i < 28; i++) {
        const s = document.createElement('span'), side = Math.random() < .5 ? -1 : 1;
        const ang = -Math.PI / 2 + (Math.random() - .5) * 2.9, d = 40 + 110 * Math.random();
        s.className = 'ember';
        s.style.left = r.left + r.width / 2 + side * r.width * (.15 + .3 * Math.random()) + 'px';
        s.style.top = r.top + r.height / 2 + 'px';
        document.body.append(s);
        s.animate([
          { transform: 'translate(-50%, -50%) scale(1)', opacity: 1 },
          { transform: `translate(calc(-50% + ${Math.cos(ang) * d}px), calc(-50% + ${Math.sin(ang) * d * .8 + 20}px)) scale(.4)`, opacity: 0 },
        ], { duration: 700 + 500 * Math.random(), delay: 120 * Math.random(), easing: 'cubic-bezier(.23, 1, .32, 1)', fill: 'backwards' })
          .onfinish = () => s.remove();
      }
    }
    
    // demo: plays until you click or type anything
    let demo = true;
    const stopDemo = () => {
      if (!demo) return;
      demo = false;
      mailField.classList.remove('lit'); passField.classList.remove('lit');
      reset();
    };
    addEventListener('pointerdown', stopDemo, true);
    addEventListener('keydown', stopDemo, true);
    
    function reset() {
      email.value = pass.value = '';
      passField.classList.remove('show', 'inside'); eye.setAttribute('aria-pressed', false);
      send.classList.remove('done'); night.classList.remove('day');
      paintPassword(false); dive = null;
    }
    
    async function play() {
      goal = at(email);
      await wait(650); if (!demo) return;
      mailField.classList.add('lit');
      for (const ch of 'you@example.com') { if (!demo) return; email.value += ch; goal = caretGoal(email); await wait(42); }
      await wait(300); if (!demo) return;
      mailField.classList.remove('lit'); passField.classList.add('lit');
      for (const ch of 'fireflies') { if (!demo) return; pass.value += ch; paintPassword(true); diveIntoPassword(); await wait(pass.value.length === 1 ? 380 : 72); }
      await wait(250); if (!demo) return;
      dive = null; passField.classList.remove('inside', 'lit');
      goal = { x: at(eye).x, y: passField.getBoundingClientRect().top - 18 };
      await wait(320); if (!demo) return;
      goal = at(eye);
      await wait(300); if (!demo) return;
      eye.click();
      await wait(380); if (!demo) return;
      form.requestSubmit();
      await wait(3600); if (!demo) return;
      reset(); goal = { x: -60, y: innerHeight / 2 };
      await wait(1400); if (demo) play();
    }
    play();

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

Отправляйте логин и пароль из signIn() на свой сервер и возвращайте true, если они верные. На живом сайте никогда не проверяйте пароли в браузере.

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

Tilda, Webflow, WordPress

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

Tilda

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

Webflow

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

WordPress

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

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

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