🔥 Description
This component creates a stylish elastic bouncing navigation bar with a liquid glass effect, animated movement indicator, and smooth interaction based on mouse hover and click events. JavaScript handles the easing, the SVG filter creates the distortion wave, and CSS creates the frosted glass styling and layout.
🧠 How the Component Works
📄 HTML Code
🌐 1️⃣ HTML Explanation
The HTML provides the structure for the navigation effect and the full-page scrolling sections:
✔ Header & Navigation
The nav contains an ul list where each li holds a navigation link (a). This simple list-based structure is used so JavaScript can easily measure each item’s position and animate the indicator under it.
✔ Sections
Four sections (#section1 to #section4) are placed vertically, each containing a full-screen image. This is mainly for demonstrating smooth scrolling and navigation interactions.
✔ SVG Filter
A hidden svg section defines a "wave-distort" filter using:
feTurbulence
feGaussianBlur
feComposite
feDisplacementMap
This filter creates a distorted water/glass reflection effect, applied to the navigation bar using CSS backdrop-filter: url(#wave-distort).
✔ Script
" script src="./script.js" loads the animation logic that controls the bouncing indicator.
🎨 CSS Code
🎨 2️⃣ CSS Explanation
The CSS handles all visual appearance, layout behavior, and the liquid-glass effect.
✔ Global Reset
Resets margins, paddings, and enables smooth scrolling.
✔ Full-Screen Sections
.container is styled to fill the full viewport height with centered content. Images use object-fit: cover to maintain quality across screen sizes.
✔ Frosted Glass Navigation
The nav is:
Centered horizontally
Given a blurred, semi-transparent, glass-like background
Surrounded by a soft shadow
Distorted using the custom SVG filter
This creates a "liquid glass" floating bar.
✔ Indicator Animation Styles
nav > ul::after creates the circular glowing indicator:
White glowing spot
Moves elastically based on CSS variables set by JavaScript
Appears only when .show-indicator is added
It visually "jumps" between items when hovered.
✔ Link Hover/Active Styles
Links:
Rise slightly upward when hovered
Become bold and darker
Have smooth cubic-bezier transitions for natural movement
✔ Responsive Glass
The nav uses overflow: hidden; and backdrop-filter so the distortion effect applies only inside the glass area.
🧠 JavaScript Code
⚙️ 3️⃣ JavaScript Explanation
JavaScript is responsible for the elastic bounce animation and dynamic indicator movement.
✔ Element Selection
JavaScript selects:
The ul inside nav
All the a items
Stores active item state and animation control variables
✔ Custom Easing Animation
A custom animation loop moves the indicator using:
Cubic easing
Vertical bounce (-40 * (4 * e * (1 - e)))
Rotation effect (200 * Math.sin(p * Math.PI))
These create the "jump + bounce + spin" behavior of the indicator.
✔ getItemCenter()
Calculates the exact center of each menu item relative to the nav bar. This ensures the indicator always aligns perfectly under each link.
✔ moveToItem()
Moves the indicator to the hovered or active item’s position by triggering the animation.
✔ setActiveItem()
Adds or removes the .active class to links, visually marking the selected section.
✔ Mouse Enter / Leave Events
On hover → indicator jumps On leave → indicator returns to the last active item
✔ Initial Activation
On page load, the first item ("Home") automatically becomes active after a slight delay.
