146 lines
3.3 KiB
Markdown
146 lines
3.3 KiB
Markdown
---
|
||
name: motion/hover-micro-interaction
|
||
title: Hover Micro-interactions
|
||
description: Subtle animations on hover: scale, shadow, border glow, color shift.
|
||
tags: [motion, hover, micro-interaction, subtle, premium]
|
||
source: linear.app, raycast.com, stripe.com, resend.com
|
||
---
|
||
|
||
# Hover Micro-interactions
|
||
|
||
## Что это
|
||
Микровзаимодействия при наведении: плавные изменения масштаба, тени, свечения бордера, цветового сдвига. Создают ощущение живого интерфейса.
|
||
|
||
## Типы hover-эффектов
|
||
|
||
### 1. Card Lift + Shadow
|
||
```css
|
||
.card {
|
||
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
||
}
|
||
.card:hover {
|
||
transform: translateY(-4px);
|
||
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
|
||
}
|
||
```
|
||
|
||
### 2. Border Glow
|
||
```css
|
||
.card {
|
||
border: 1px solid var(--color-border);
|
||
transition: border-color 0.3s ease;
|
||
}
|
||
.card:hover {
|
||
border-color: var(--color-accent);
|
||
box-shadow: 0 0 20px rgba(99, 102, 241, 0.2);
|
||
}
|
||
```
|
||
|
||
### 3. Image Zoom
|
||
```css
|
||
.image-wrapper {
|
||
overflow: hidden;
|
||
border-radius: 16px;
|
||
}
|
||
.image-wrapper img {
|
||
transition: transform 0.5s ease;
|
||
}
|
||
.image-wrapper:hover img {
|
||
transform: scale(1.05);
|
||
}
|
||
```
|
||
|
||
### 4. Text Color Shift
|
||
```css
|
||
.link {
|
||
color: var(--color-text-secondary);
|
||
position: relative;
|
||
transition: color 0.3s ease;
|
||
}
|
||
.link:hover {
|
||
color: var(--color-accent);
|
||
}
|
||
.link::after {
|
||
content: '';
|
||
position: absolute;
|
||
bottom: -2px;
|
||
left: 0;
|
||
width: 0;
|
||
height: 2px;
|
||
background: var(--color-accent);
|
||
transition: width 0.3s ease;
|
||
}
|
||
.link:hover::after {
|
||
width: 100%;
|
||
}
|
||
```
|
||
|
||
### 5. Icon Rotation/Swing
|
||
```css
|
||
.icon {
|
||
transition: transform 0.3s ease;
|
||
}
|
||
.icon:hover {
|
||
transform: rotate(15deg) scale(1.1);
|
||
}
|
||
```
|
||
|
||
## Magnetic Hover (Enhanced)
|
||
|
||
```css
|
||
.hover-magnetic {
|
||
transition: transform 0.2s ease;
|
||
}
|
||
.hover-magnetic:hover {
|
||
transform: scale(1.02);
|
||
}
|
||
```
|
||
|
||
```javascript
|
||
document.querySelectorAll('.hover-magnetic').forEach(el => {
|
||
el.addEventListener('mousemove', (e) => {
|
||
const rect = el.getBoundingClientRect();
|
||
const x = (e.clientX - rect.left) / rect.width - 0.5;
|
||
const y = (e.clientY - rect.top) / rect.height - 0.5;
|
||
el.style.transform = `perspective(500px) rotateY(${x * 10}deg) rotateX(${-y * 10}deg) scale(1.02)`;
|
||
});
|
||
el.addEventListener('mouseleave', () => {
|
||
el.style.transform = 'perspective(500px) rotateY(0) rotateX(0) scale(1)';
|
||
});
|
||
});
|
||
```
|
||
|
||
## Anti-patterns
|
||
|
||
| ❌ Плохо | ✅ Хорошо |
|
||
|----------|-----------|
|
||
| `transform: scale(1.2)` — слишком резко | `transform: scale(1.02–1.05)` |
|
||
| Без `transition` | `transition: all 0.3s ease` |
|
||
| Без `will-change` на тяжёлых | `will-change: transform` |
|
||
| Hover на touch-устройствах | `@media (hover: hover)` |
|
||
|
||
## Mobile Detection
|
||
|
||
```css
|
||
@media (hover: none) {
|
||
.hover-effect:hover {
|
||
transform: none;
|
||
}
|
||
}
|
||
```
|
||
|
||
## CV Service Validation
|
||
|
||
```bash
|
||
curl -s -X POST http://localhost:8001/design/analyze \
|
||
-H "Content-Type: application/json" \
|
||
-d '{"image_base64": "...", "full_analysis": false}' | python3 -c "
|
||
import sys, json
|
||
d = json.load(sys.stdin)
|
||
motion = d['dimensions'].get('motion_quality', {})
|
||
print(f\"Motion Quality: {motion.get('score', 'N/A')}/10\")
|
||
"
|
||
```
|
||
|
||
Ожидается: `motion_quality` > 6.
|