jQuery Hover Animation: A Simple Guide
✅ What Is hover() in jQuery?
The .hover() method in jQuery lets you define two behaviors:
-
One when the mouse enters an element
-
One when the mouse leaves the element
Syntax:
Example: Animate a Box on Hover
HTML
CSS (optional styling)
⚙️ jQuery Hover Animation
Output
When you hover over the box:
-
It smoothly grows in size
-
Its opacity fades slightly
-
When you move the mouse away, it returns to normal
Bonus: Change Background on Hover
You can also combine .css() or .toggleClass() with hover():
✅ Summary
| Method | Description |
|---|---|
.hover() |
Triggers two functions: enter + leave |
.animate() |
Smoothly changes numeric CSS properties |
.css() |
Instantly changes CSS styles |
