Direction-Aware Hover Effect
A card overlay that enters from the edge the pointer crossed, and leaves by the edge it exits.

A direction-aware hover watches which edge of a card the pointer crosses and brings the overlay in from that edge. Leaving reverses it: the overlay exits through the edge you used to leave. A normal fade has no memory of the pointer. This one does, which is why the search (“direction aware hover”, “hover effect from mouse side”) has stayed around since the early jQuery plugins. The modern version is a few lines that set a data-side and a class. No plugin.
The overlay is a full-card panel with the longer description. The card’s own label stays put. When the overlay is off-canvas it does not cover the label. When it is in, it carries the sentence. That is a better job than sliding the photograph itself, which makes the image hard to see at the exact moment someone showed interest.
Pair it with the spotlight card when you want light instead of a panel, and with unveiling card details when the hidden content should feel like a flap rather than a direction.
Which edge?
Compare the pointer to the center of the card. If the horizontal distance is larger, the pointer is on the left or the right. Otherwise it is on the top or the bottom.
function side(event, card) {
const rect = card.getBoundingClientRect();
const x = (event.clientX - rect.left) / rect.width - 0.5;
const y = (event.clientY - rect.top) / rect.height - 0.5;
if (Math.abs(x) > Math.abs(y)) return x > 0 ? "right" : "left";
return y > 0 ? "bottom" : "top";
}
Using the center, not a set of corner triangles, is accurate enough for a rectangle and much shorter. The overlay’s travel is the full width or height, so a slightly wrong edge near a corner is still a plausible entrance.
Enter without a flash
The cover must snap to the entry edge with no transition, then animate to transform: none. If the transition is always on, changing data-side slides the cover along the outside of the card before it enters.
card.addEventListener("mouseenter", (event) => {
card.classList.remove("is-armed", "is-in");
card.dataset.side = side(event, card);
void card.offsetWidth;
card.classList.add("is-armed", "is-in");
});
card.addEventListener("mouseleave", (event) => {
card.dataset.side = side(event, card);
card.classList.remove("is-in");
});
is-armed is what allows the transition. Removing it, setting the side, and reading offsetWidth forces the snap. Adding it back with is-in plays the entrance. On leave, is-armed stays, the side updates to the exit edge, and removing is-in plays the exit. void card.offsetWidth is the reflow. Without it the browser can collapse the snap and the animation into one frame.
.card[data-side="left"] .cover { transform: translateX(-100%); }
.card[data-side="right"] .cover { transform: translateX(100%); }
.card[data-side="top"] .cover { transform: translateY(-100%); }
.card[data-side="bottom"] .cover { transform: translateY(100%); }
.card.is-armed .cover { transition: transform .45s cubic-bezier(.2,.7,.2,1); }
.card.is-in .cover { transform: none; }
.is-in comes last so it wins while the card is open. The side rule is the resting place outside the card.
Touch
A hover direction does not exist on a tap in any way a person can feel. On a coarse pointer, show the description without the slide, or make the card a link and put the description on the next page. The effect is for a mouse. Shipping it as the only way to read the sentence fails on a phone. The card label in this demo (“Atelier”, “Harbor”, “Field”, “Grove”) is visible before hover, so the overlay is extra, not required.
Questions about direction-aware hovers
How does a direction-aware hover effect work?
On enter and leave, compare the pointer to the card’s center and name the nearest edge. Park the overlay just outside that edge, then animate it in. On leave, park it outside the exit edge and animate it out.
Why does my overlay flash before it slides?
The side changed while a transition was active, so the overlay animated to its hiding place and then in. Turn the transition off, set the side, force layout, then turn the transition on and show the overlay.
Can I build this in CSS without JavaScript?
You can detect :hover. You cannot know which edge was crossed, because CSS does not get the pointer coordinate relative to the card on enter. The function above is the whole script.