feat(our-tools): calm subtle expansion ratio and scroll-triggered middle-viewport activation
This commit is contained in:
@@ -104,6 +104,28 @@ export function ShiftableToolsGridSection({
|
||||
const row1 = displayItems.slice(0, 4);
|
||||
const row2 = displayItems.slice(4, 8);
|
||||
|
||||
// Expansion only starts when that section reaches the middle (top of section <= 50% of viewport)
|
||||
const [isMiddleReached, setIsMiddleReached] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const checkPosition = () => {
|
||||
const section = document.getElementById('our-tools');
|
||||
if (!section) return;
|
||||
const rect = section.getBoundingClientRect();
|
||||
// Only start expansion once the section reaches the middle of the viewport
|
||||
const inMiddle = rect.top <= window.innerHeight * 0.5 && rect.bottom >= window.innerHeight * 0.15;
|
||||
setIsMiddleReached(inMiddle);
|
||||
};
|
||||
|
||||
checkPosition();
|
||||
window.addEventListener('scroll', checkPosition, { passive: true });
|
||||
window.addEventListener('resize', checkPosition, { passive: true });
|
||||
return () => {
|
||||
window.removeEventListener('scroll', checkPosition);
|
||||
window.removeEventListener('resize', checkPosition);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<section id="our-tools" className="py-14 sm:py-20 px-4 sm:px-6 md:px-8 lg:px-10 bg-[#FAF8F5] relative overflow-hidden">
|
||||
{/* Symbolic Elemental Ambient Highlights */}
|
||||
@@ -136,8 +158,8 @@ export function ShiftableToolsGridSection({
|
||||
|
||||
{/* Desktop View (md and up): 2-Row Shiftable Expansion Grid */}
|
||||
<div className="hidden md:block space-y-8">
|
||||
<ShiftableRow items={row1} />
|
||||
<ShiftableRow items={row2} />
|
||||
<ShiftableRow items={row1} isEnabled={isMiddleReached} />
|
||||
<ShiftableRow items={row2} isEnabled={isMiddleReached} />
|
||||
</div>
|
||||
|
||||
{/* Mobile / Phone View (<md): Pure Vertical Stack (NOT placed horizontally) */}
|
||||
@@ -204,29 +226,37 @@ function MobileVerticalToolsList({ items }: { items: ToolMediaItem[] }) {
|
||||
);
|
||||
}
|
||||
|
||||
function ShiftableRow({ items }: { items: ToolMediaItem[] }) {
|
||||
function ShiftableRow({ items, isEnabled = true }: { items: ToolMediaItem[]; isEnabled?: boolean }) {
|
||||
const [hoveredId, setHoveredId] = useState<string | null>(null);
|
||||
|
||||
// Clear any active hover expansion if the section leaves the active middle viewport zone
|
||||
useEffect(() => {
|
||||
if (!isEnabled) {
|
||||
setHoveredId(null);
|
||||
}
|
||||
}, [isEnabled]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-row gap-6 w-full items-start overflow-visible">
|
||||
{items.map((item) => {
|
||||
const isHovered = hoveredId === item.id;
|
||||
const hasOtherHovered = hoveredId !== null && !isHovered;
|
||||
const isHovered = isEnabled && hoveredId === item.id;
|
||||
const hasOtherHovered = isEnabled && hoveredId !== null && !isHovered;
|
||||
|
||||
// Slow, calm, luxurious horizontal expansion:
|
||||
// When hovered: 1.85 flex-grow (~46% width)
|
||||
// When other is hovered: 0.716 flex-grow (~18% width)
|
||||
// At rest: 1.0 flex-grow (25% width each)
|
||||
// Sum is always mathematically conserved at exactly 4.0 (1.85 + 3 * 0.716 = 4.00)
|
||||
// Fixed flex-basis: 0 eliminates conflicting layout calculations
|
||||
const flexGrowValue = isHovered ? 1.85 : hasOtherHovered ? 0.716 : 1;
|
||||
// Subtle, refined expansion (lesser shift, lesser expansion):
|
||||
// Hovered card: 1.28 flex-grow (~32% width, gentle expansion)
|
||||
// Other cards: 0.9066 flex-grow (~22.6% width, minimal displacement)
|
||||
// At rest or before middle reached: 1.0 flex-grow (25% width each)
|
||||
// Sum is mathematically conserved at exactly 4.0 (1.28 + 3 * 0.9066 = 4.00)
|
||||
const flexGrowValue = isHovered ? 1.28 : hasOtherHovered ? 0.9066 : 1;
|
||||
|
||||
return (
|
||||
<div
|
||||
key={item.id}
|
||||
onMouseEnter={() => setHoveredId(item.id)}
|
||||
onMouseEnter={() => {
|
||||
if (isEnabled) setHoveredId(item.id);
|
||||
}}
|
||||
onMouseLeave={() => setHoveredId(null)}
|
||||
className="w-[82vw] max-w-[320px] md:max-w-none md:w-auto shrink-0 md:shrink md:flex-1 snap-start transition-[flex-grow] duration-700 ease-[cubic-bezier(0.16,1,0.3,1)] flex flex-col min-w-0"
|
||||
className="w-[82vw] max-w-[320px] md:max-w-none md:w-auto shrink-0 md:shrink md:flex-1 snap-start transition-[flex-grow] duration-500 ease-[cubic-bezier(0.16,1,0.3,1)] flex flex-col min-w-0"
|
||||
style={{
|
||||
flexGrow: flexGrowValue,
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user