Compare commits
2 Commits
version_29
...
version_30
| Author | SHA1 | Date | |
|---|---|---|---|
| daab93c9f3 | |||
| a2228ca537 |
@@ -16,35 +16,52 @@ export default function LandingPage() {
|
||||
const [showModal, setShowModal] = useState(false);
|
||||
const [showBackToTop, setShowBackToTop] = useState(false);
|
||||
const [showViewMoreButton, setShowViewMoreButton] = useState(false);
|
||||
const [scrollDirection, setScrollDirection] = useState<'up' | 'down'>('down');
|
||||
const [lastScrollY, setLastScrollY] = useState(0);
|
||||
const viewMoreButtonRef = useRef<HTMLDivElement>(null);
|
||||
const sixthItemRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let ticking = false;
|
||||
|
||||
const handleScroll = () => {
|
||||
setShowBackToTop(window.scrollY > 300);
|
||||
if (!ticking) {
|
||||
window.requestAnimationFrame(() => {
|
||||
const currentScrollY = window.scrollY;
|
||||
setShowBackToTop(currentScrollY > 300);
|
||||
|
||||
// Determine scroll direction
|
||||
if (currentScrollY > lastScrollY) {
|
||||
setScrollDirection('down');
|
||||
} else {
|
||||
setScrollDirection('up');
|
||||
}
|
||||
setLastScrollY(currentScrollY);
|
||||
|
||||
// Check if 6th item is in view
|
||||
if (sixthItemRef.current) {
|
||||
const rect = sixthItemRef.current.getBoundingClientRect();
|
||||
const isInView = rect.top < window.innerHeight && rect.bottom > 0;
|
||||
const isScrollingDown = scrollDirection === 'down';
|
||||
|
||||
// Show button when 6th item is reached AND scrolling down
|
||||
// Hide button when scrolling back up past the 6th item
|
||||
if (isInView && isScrollingDown) {
|
||||
setShowViewMoreButton(true);
|
||||
} else if (!isInView && scrollDirection === 'up') {
|
||||
setShowViewMoreButton(false);
|
||||
}
|
||||
}
|
||||
|
||||
ticking = false;
|
||||
});
|
||||
ticking = true;
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('scroll', handleScroll);
|
||||
return () => window.removeEventListener('scroll', handleScroll);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const observer = new IntersectionObserver(
|
||||
([entry]) => {
|
||||
setShowViewMoreButton(entry.isIntersecting);
|
||||
},
|
||||
{ threshold: 0.1 }
|
||||
);
|
||||
|
||||
if (viewMoreButtonRef.current) {
|
||||
observer.observe(viewMoreButtonRef.current);
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (viewMoreButtonRef.current) {
|
||||
observer.unobserve(viewMoreButtonRef.current);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
}, [lastScrollY, scrollDirection]);
|
||||
|
||||
const scrollToGallery = () => {
|
||||
const gallerySectionElement = document.getElementById('gallery');
|
||||
@@ -419,16 +436,19 @@ export default function LandingPage() {
|
||||
products={initialDresses}
|
||||
/>
|
||||
|
||||
{/* View More Button - Positioned after 6th picture, visible when 6th item is in view */}
|
||||
<div ref={viewMoreButtonRef} className="relative mt-0">
|
||||
{showViewMoreButton && (
|
||||
{/* Reference to 6th item for scroll detection */}
|
||||
<div ref={sixthItemRef} className="absolute pointer-events-none" style={{ height: 0, top: 'calc(100% - 500px)' }} />
|
||||
|
||||
{/* More Button - Positioned after 6th picture, visible when 6th item is reached and scrolling down */}
|
||||
<div className="relative mt-0">
|
||||
{showViewMoreButton && scrollDirection === 'down' && (
|
||||
<div className="absolute -top-[280px] right-8 lg:right-16 z-30 flex justify-end animate-in fade-in slide-in-from-bottom-4 duration-300">
|
||||
<button
|
||||
onClick={() => setShowModal(true)}
|
||||
className="group relative inline-flex items-center gap-2 px-4 md:px-6 py-2 md:py-3 bg-gradient-to-r from-[#D4AF37] to-[#D4AF37] text-black rounded-lg font-semibold hover:shadow-lg transition-all duration-300 ease-out shadow-lg"
|
||||
aria-label="View More Dresses"
|
||||
>
|
||||
<span className="text-sm md:text-base">View More Dresses</span>
|
||||
<span className="text-sm md:text-base">More</span>
|
||||
<ChevronRight className="w-4 h-4 md:w-5 md:h-5 group-hover:translate-x-1 transition-transform" />
|
||||
</button>
|
||||
</div>
|
||||
@@ -660,4 +680,4 @@ export default function LandingPage() {
|
||||
</div>
|
||||
</ThemeProvider>
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user