Advertisement

Hover Image Reveal Custom Cursor

| by Vladimir | 2 min read | code by Ivan Grozdic
Intermediate

Tech & Dependencies

HTML CSS JavaScript

Features

  • Custom Cursor
  • Image Reveal
  • State Delegation
  • Blend Modes

Browser Support

Chrome 49+ Edge 16+ Firefox 54+ Safari 10.1+

Core

This is a Hover Image Reveal Custom Cursor. It overrides the default pointer with a dynamic element that transforms upon interacting with specific text links. Its function is to provide visual context — revealing associated images — without cluttering the primary layout. The effect creates an engaging reading experience, bridging text and multimedia seamlessly.

Specs

  • Weight: ~3 KB.
  • Dependencies: None.
  • Browser Support: Modern browsers supporting CSS Custom Properties and mix-blend-mode.
  • [!] Accessibility: Relies entirely on pointer movement. Invisible to keyboard navigation and touch devices.

Anatomy

The component separates structural content from the interactive layer.

  • HTML (The Skeleton): Uses a standard text block with inline anchor tags (.hover-target). Three empty div elements act as the custom cursor layers (#cursor, #cursor2, #cursor3).
  • CSS (The Skin): CSS variables handle the color palette. The .cursor classes use position: fixed to float above the content and track viewport coordinates. The mix-blend-mode: difference property is applied to the text hover pseudo-elements for a stark, inverted contrast effect.
  • JS (The Nervous System): A mousemove listener continuously updates the left and top inline styles of the cursor divs. Additional mouseenter and mouseleave listeners are attached to the links to trigger state changes.

Logic

The elegance of this snippet lies in its state delegation mechanism. Instead of manipulating the cursor’s styling directly via JavaScript, the script delegates the visual state to CSS by modifying the body tag.

hoverLink.addEventListener('mouseenter', function (e) {
    bodychange.classList.add('img-1-wrap');
});

This Glyph-logic triggers the corresponding CSS rule, which handles the image injection and dimensional changes:

body.img-1-wrap .cursor2 {
  background-image: url('...');
  height: 220px;
  width: 320px;
}

This separation of concerns keeps the JS extremely lightweight and leverages the browser’s CSS engine for smoother, hardware-accelerated transitions.

Feel

The interaction feels exploratory and rewarding. The cursor follows the mouse with immediate precision. When hovering over a link, the cursor seamlessly expands into a responsive image frame. It physically erases the gap between reading plain text and viewing multimedia, making content discovery fluid and dynamic.

Advertisement