Skip to content
animorio
IT
Back to the library

Corner-snapping video

Physics, HoverGSAP, CanvasMediumCompressed weight: Demo 8.3 KBGSAP 28 KBFreeDownload the zip

A small picture-in-picture video window over a document page, in the clean style of today’s apps: you drag it with a finger and, let go, it flies with the momentum of the throw toward the nearest corner in the direction you threw it, snapping in on a short spring that bounces by a pixel. Pulled past a side it tucks into a tab, and a tap brings it back.

The code

A folder that runs on its own: index.html, style.css, script.js and the libraries from a CDN. The React and Vue tabs hold the same demo as a ready component, which switches its animations off when it leaves the page.

<!doctype html>
<!--
  "Corner-snapping video" from Animorio · https://animorio.com
  License: free on your own sites and your clients’ sites, paid work included.
  Not for resale, redistribution, templates or code collections · https://animorio.com/en/license/
-->
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>The video window that snaps to the corners</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <main class="stage" data-stage>
    <!-- a document app with a picture-in-picture video: drag it, fling it and it flies to the nearest corner
         in the direction of the throw, snapping on a short spring; pull it past a side and it tucks into a tab -->
    <section class="app" data-app aria-label="Paperlane document with a floating video">
      <header class="app__bar">
        <div class="app__brand">
          <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 3.5h8.5L19 8v12.5H6Z"></path><path d="M14.5 3.5V8H19"></path></svg>
          <span>Paperlane</span>
        </div>
        <p class="app__crumb">Launch plan <span class="app__sep">/</span> <b>Q4 roadmap review</b></p>
        <div class="app__share">Share</div>
      </header>

      <div class="doc" data-doc>
        <div class="doc__page">
          <p class="doc__kicker">Notes · Oct 26</p>
          <h1 class="doc__title">Q4 roadmap review</h1>
          <div class="doc__lines">
            <i style="width:92%"></i><i style="width:84%"></i><i style="width:88%"></i><i style="width:46%"></i>
            <i class="gap" style="width:30%"></i>
            <i style="width:90%"></i><i style="width:76%"></i><i style="width:86%"></i><i style="width:58%"></i>
            <i class="gap" style="width:26%"></i>
            <i style="width:88%"></i><i style="width:80%"></i><i style="width:40%"></i>
          </div>
        </div>

        <!-- the four snap zones: they light up faintly while the window is held -->
        <div class="zone" data-zone="0"></div><div class="zone" data-zone="1"></div>
        <div class="zone" data-zone="2"></div><div class="zone" data-zone="3"></div>

        <div class="pip" data-pip role="group" aria-label="Floating video, drag to move">
          <div class="pip__body" data-body>
            <canvas class="pip__video" data-video></canvas>
            <div class="pip__top">
              <span class="pip__live">Recording</span>
              <span class="pip__name">Launch keynote</span>
            </div>
            <div class="pip__controls" data-controls>
              <button type="button" class="pip__btn" aria-label="Pause"><svg viewBox="0 0 24 24"><path d="M9 6.5v11M15 6.5v11"></path></svg></button>
              <button type="button" class="pip__btn" aria-label="Back to the tab"><svg viewBox="0 0 24 24"><path d="M14 5h5v5M19 5l-7 7M10 5H5v14h14v-5"></path></svg></button>
              <button type="button" class="pip__btn" aria-label="Close"><svg viewBox="0 0 24 24"><path d="M7 7l10 10M17 7 7 17"></path></svg></button>
            </div>
            <div class="pip__foot">
              <span class="pip__time" data-time>12:48</span>
              <div class="pip__track"><div class="pip__fill" data-fill></div></div>
              <span class="pip__time pip__time--end">41:02</span>
            </div>
          </div>
          <!-- the tab shown when the window is tucked away at a side -->
          <button type="button" class="pip__tab" data-tab aria-label="Bring the video back">
            <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M14.5 6.5 9 12l5.5 5.5"></path></svg>
          </button>
        </div>
      </div>
    </section>

    <svg class="ghost" data-ghost viewBox="0 0 24 24" aria-hidden="true"><path d="M5 3.2 19.2 11l-6.3 1.6-3.3 5.9Z"></path></svg>
  </main>

  <script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
  <script src="script.js"></script>
</body>
</html>

Playground

Change values, colours and text with the controls and watch the animation respond live. Or write in the code yourself. Then download the folder with your changes.

26 values to change

Or ask your AI assistant for it

With the Animorio connector, Claude Code, ChatGPT, Cursor or VS Code take it from here, guide included, and fit it into your project. Paste this request:

Take “Corner-snapping video” from Animorio and fit it into my site
Platform licenseFree on your sites and your clients’ sites. Want it inside a website builder, a template platform or a client dashboard? There’s a license for agencies and platforms.

What it does

On a very light grey background there is the window of Paperlane, a made-up document app: the bar at the top with the name, the path Launch plan / Q4 roadmap review and the Share button, and below the notes page with its title and the grey lines of text. In the bottom right corner floats a small video window, the Launch keynote recording: soft colour fields drifting slowly under a fine grain, a pale slide in the middle, the Recording label at the top and at the bottom the progress bar with the time running. Hovering it, three round glass buttons appear in the middle: pause, back to the tab, close. Grabbed, the window lifts a little and its shadow spreads, and in the four corners of the page the snap zones light up faintly, dashed and washed with indigo: the one the throw would land in is brighter than the others and changes as you move. Let go, the window flies with the speed it had toward the corner the throw chose, gets there on a short spring, goes a pixel past and settles; the shadow tightens again with a small bounce. Pulled past the right or left edge, the window leaves the page and only a black tab with an arrow stays on the side: a tap brings it back to the nearest corner. A drawn pointer shows it all: it hovers, throws the window to the top left, then to the right, then pulls it past the side and brings it back from the tab; the first real touch stops it.

How it works

The throw that picks the corner

While dragging, the window keeps the last 90 milliseconds of positions and derives its speed from them. On release the landing point is projected forward, position plus velocity times THROW seconds, and the corner is the quadrant the projected centre falls in: a flick upward takes it to the top even if you let go low on the page.

A spring written by hand

The flight to the corner is not a tween but a spring integrated every frame in GSAP’s ticker, split into 8 millisecond steps: the acceleration is minus the stiffness times the distance, minus the damping times the speed. The window starts with the real speed of the throw, and with a damping of 0.8 it goes a pixel past the corner and comes back.

The snap zones

The four zones are dashed rectangles, with the accent colour mixed in the script rather than with color-mix in the CSS, because the preview recorder doesn’t draw it. While the window is held, every move recomputes the landing corner and its zone rises to full opacity while the others stay at 40%.

The tab on the side

If the projected centre leaves the page, the spring carries the window just past the side and a tab, a child of the window, stays inside the page with an arrow pointing the way back. A tap returns it to the corner on that side closest to the height where it was tucked.

The painted video

The recording is a canvas redrawn every frame by the same ticker: three radial gradients added in lighter mode moving on slow sines, a pale slide and a grain pattern shifted slowly. The bar and the clock move on with GSAP’s clock.

Values to change

NameFileDefaultWhat it changes
SIZEscript.js0.34How wide the video window is compared to the page.
STIFFNESSscript.js380The stiffness of the spring that snaps it to the corner: higher is quicker.
DAMPINGscript.js0.8The spring’s damping: 1 with no bounce, lower bounces more.
THROWscript.js0.2How much the throw counts: the seconds of flight used to pick the corner.
MARGINscript.js14The gap between the window and the edge of the page, in pixels.
ACCENTscript.js#4f46e5The colour of the snap zones.
HOLDscript.js1.4The seconds of pause between one throw and the next of the drawn pointer.

Try them in the Playground

When to use it

For an app with calls or videos that stay open while you work: a lesson, a meeting, a live stream or a tutorial that follows someone writing a document, without covering their text.

On phones

The same physics with a finger: the app window is sized on the width and the height of the box, the video window stays at least 140 pixels wide and the corners are recomputed on every resize.

With reduced motion

No flight and no spring: let go, the window fades out and reappears in the chosen corner; there is no drawn pointer and the window moves from corner to corner with a fade.

Pitfalls

  • The zone colour made with color-mix in the CSS doesn’t show in the recorded previews: the accent colour must be mixed in the script.
  • Picking the corner from the release position instead of the projected one sends a hard-thrown window back where it came from: without the projection the gesture feels ignored.
  • The window GSAP moves and the one that grows are two different elements, the window and its body: otherwise the scale of holding it would wipe the position.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

Compressed with gzip, the three demo files weigh 8.3 KB; the libraries: GSAP 28 KB.

Testing

Tested on 26 October 2026

  • Desktop: Done
  • Phone: Done
  • Reduced motion: Done
  • Safari on iPhone: To do

License

Use it in your own projects and in your clients’ projects. Do not resell it or redistribute it as is. GSAP stays under its own Standard license. Full license.

All animations