"use client"; import Image from "next/image"; import { useEffect } from "react"; export default function Testimonials() { useEffect(() => { const container = document.querySelector(".circle-container"); if (!container) return; const outerElements = document.querySelectorAll(".outer-element"); const innerElements = document.querySelectorAll(".inner-element"); const testimonialElements = document.querySelectorAll(".testimonial"); let angle = 0, innerAngle = 0; const rotationSpeed = 0.0005, innerRotationSpeed = -0.001; let outerPaused = false; let innerPaused = false; let animationFrameId; function updateElementWidth() { const width = container.offsetWidth; container.style.setProperty("--circle-container-width", `${width}px`); } function updatePositions() { const containerWidth = container.offsetWidth; const outerRadius = containerWidth / 2.08; const innerRadius = containerWidth / 3.4; if (!outerPaused) { outerElements.forEach((element, index) => { const avatarAngle = angle + index * ((2 * Math.PI) / outerElements.length); element.style.transform = `translate(${ Math.cos(avatarAngle) * outerRadius }px, ${Math.sin(avatarAngle) * outerRadius}px)`; }); } if (!innerPaused) { innerElements.forEach((element, index) => { const elemAngle = innerAngle + index * ((2 * Math.PI) / innerElements.length); element.style.transform = `translate(${ Math.cos(elemAngle) * innerRadius }px, ${Math.sin(elemAngle) * innerRadius}px)`; }); } } function animate() { if (!outerPaused) angle += rotationSpeed; if (!innerPaused) innerAngle += innerRotationSpeed; updatePositions(); animationFrameId = requestAnimationFrame(animate); } function handleOuterHover(event) { if (event.type === "mouseenter") { outerPaused = true; } else { outerPaused = false; } } function handleInnerHover(event) { if (event.type === "mouseenter") { innerPaused = true; } else { innerPaused = false; } } function handleTestimonialHover(event) { const testimonial = event.currentTarget; const popup = testimonial.querySelector(".content"); if (!popup) return; const pinOffset = testimonial.getBoundingClientRect(); const pinWidth = testimonial.offsetWidth; const wrapOffset = container.getBoundingClientRect(); const popupWidth = popup.offsetWidth; const windowWidth = window.innerWidth; const windowOffsetTop = window.scrollY; const thisOffsetToWindow = pinOffset.top - windowOffsetTop; const windowHeight = window.innerHeight; if (pinOffset.left + popupWidth > windowWidth) { popup.style.left = `-${ pinOffset.left + popupWidth - windowWidth + 15 }px`; const arrow = popup.querySelector(".arrow"); if (arrow) { arrow.style.left = `${ pinOffset.left + popupWidth - windowWidth + 47 }px`; } } else { const arrow = popup.querySelector(".arrow"); if (arrow) { arrow.style.left = "auto"; } popup.style.left = "0"; } if (thisOffsetToWindow > windowHeight / 2) { popup.classList.add("top"); popup.classList.remove("bottom"); } else { popup.classList.remove("top"); popup.classList.add("bottom"); } } function handleResize() { updateElementWidth(); updatePositions(); } // Add event listeners outerElements.forEach((el) => { el.addEventListener("mouseenter", handleOuterHover); el.addEventListener("mouseleave", handleOuterHover); }); innerElements.forEach((el) => { el.addEventListener("mouseenter", handleInnerHover); el.addEventListener("mouseleave", handleInnerHover); }); testimonialElements.forEach((el) => { el.addEventListener("mouseenter", handleTestimonialHover); }); window.addEventListener("resize", handleResize); // Initialize updateElementWidth(); updatePositions(); animate(); // Cleanup return () => { cancelAnimationFrame(animationFrameId); outerElements.forEach((el) => { el.removeEventListener("mouseenter", handleOuterHover); el.removeEventListener("mouseleave", handleOuterHover); }); innerElements.forEach((el) => { el.removeEventListener("mouseenter", handleInnerHover); el.removeEventListener("mouseleave", handleInnerHover); }); testimonialElements.forEach((el) => { el.removeEventListener("mouseenter", handleTestimonialHover); }); window.removeEventListener("resize", handleResize); }; }, []); return (
Advitex provided exceptional financial guidance that transformed my investment approach. Their expertise and personalized advice made all the difference. Highly recommend!"
Senior Wealth Manager
Advitex provided exceptional financial guidance that transformed my investment approach. Their expertise and personalized advice made all the difference. Highly recommend!"
Senior Wealth Manager