Skip to content

Hover Box

The Hover Box component creates an interactive hover effect that follows the mouse cursor within an element. It adds a subtle radial gradient effect that moves with the cursor, enhancing the visual feedback for interactive elements.

This component has no additional dependencies beyond the Metro UI core.

<div data-role="hover-box">
<!-- Your content here -->
</div>
<div data-role="hover-box" style="width: 400px; height: 300px;">
<h3>Box Header</h3>
<p>Some text inside the box</p>
</div>
ParameterTypeDefaultDescription
onHoverBoxCreatefunctionMetro.noopCallback function triggered when the hover box is created
  • destroy() - Removes the hover box component and its associated elements.
const hoverBox = Metro.getPlugin('#myHoverBox', 'hoverbox');
hoverBox.destroy();
EventDescription
onHoverBoxCreateTriggered when the hover box component is created
VariableDefault (Light)Dark ModeDescription
--hover-box-effect-colorhsla(0,0%,80%,56%)hsla(234,78%,62%,26%)Color of the hover effect gradient
--x00X-coordinate for the hover effect (set automatically)
--y00Y-coordinate for the hover effect (set automatically)
--size00Size of the hover effect (set automatically based on element height)
/* Custom styling for a specific hover box */
#myCustomHoverBox {
--hover-box-effect-color: hsla(180, 100%, 50%, 0.5);
}
  • .hover-box - The main class applied to the element that creates the hover effect

The Hover Box component:

  • Only shows the hover effect on devices that support hover (using the @media (hover: hover) CSS media query)
  • Creates a radial gradient that follows the mouse cursor
  • Automatically calculates the size of the effect based on the element’s height
  • Works best with elements that have a defined height and width