Home
Showing UI on mouse move, in Svelte 5
In my note taking application Edna I’ve implemented unorthodox UI feature: in the editor a top left navigation element is only visible when you’re moving the mouse or when mouse is over the element.
Here’s UI hidden:
Here’s UI visible:
The thinking is: when writing, you want max window space dedicated to the editor.
When you move mouse, you’re not writing so I can show additional UI. In my case it’s a way to launch note opener or open a starred or recently opened note.

Implementation details

Here’s how to implement this:

Svelte 5 implementation details

This can be implemented in any web framework. Here’s how to do it in Svelte 5.
We want to use Svelte 5 reactivity. We have mouse-track.svelte.js:
class MouseMoveTracker {
  moving = $state(false);
}

export const isMoving = new MouseMoveTracker();

let timeoutId;
function onMouseMove() {
  clearTimeout(timeoutId);
  timeoutId = setTimeout(() => {
    isMoving.moving = false;
  }, 500);
  isMoving.moving = true;
}

document.addEventListener("mousemove", onMouseMove);
Here’s how we use it:
  import { isMoving } from "../mouse-track.svelte.js";

<div
  class:moving={isMoving.moving}
  class="fixed top-0 flex flex-col z-10 showOnMouseMove"
>...</div>

<style>
  .showOnMouseMove {
    visibility: hidden;
    &:where(.moving, :hover) {
      visibility: visible;
    }
  }
</style>
if mouse is moving, we add moving class to element.
We use CSS to set visibility to visible if class moving is set or on hover.
svelte programming
Jun 11 2025

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you: