header updated

This commit is contained in:
2025-11-02 19:32:26 +08:00
parent 3c39db54d2
commit 736578dae3
4 changed files with 27 additions and 23 deletions

View File

@@ -1,4 +1,4 @@
import { Box, Flex, Image, VStack, Text, Link } from '@chakra-ui/react'; import { Box, Flex, Image, VStack, Text } from '@chakra-ui/react';
import { GiHamburgerMenu } from "react-icons/gi"; import { GiHamburgerMenu } from "react-icons/gi";
import { IoCloseSharp } from "react-icons/io5"; import { IoCloseSharp } from "react-icons/io5";
import { colors } from '../colors'; import { colors } from '../colors';
@@ -69,11 +69,19 @@ function Header({ showMenu = false }: HeaderProps) {
}; };
}, []); }, []);
const scrollToSection = (sectionId: string) => {
const element = document.getElementById(sectionId.replace('#', ''));
if (element) {
element.scrollIntoView({ behavior: 'smooth' });
}
setIsDrawerOpen(false);
};
const menuItems = [ const menuItems = [
{ label: '40+常見健康問題', href: '#info' }, { label: '40+常見健康問題', id: 'info' },
{ label: '營萃護心油四大優勢', href: '#advantages' }, { label: '營萃護心油四大優勢', id: 'advantages' },
{ label: '護心食譜', href: '#recipes' }, { label: '護心食譜', id: 'recipes' },
{ label: '更多食用油健康真相', href: '#truth' }, { label: '更多食用油健康真相', id: 'truth' },
]; ];
return ( return (
@@ -143,24 +151,18 @@ function Header({ showMenu = false }: HeaderProps) {
> >
<VStack align="stretch" gap={4} mt={4}> <VStack align="stretch" gap={4} mt={4}>
{menuItems.map((item, index) => ( {menuItems.map((item, index) => (
<Link <Box
key={index} key={index}
href={item.href} onClick={() => scrollToSection(item.id)}
onClick={() => setIsDrawerOpen(false)} p={3}
textDecoration="none" borderRadius="md"
_hover={{ textDecoration: 'none' }} _hover={{ bg: 'gray.100' }}
cursor="pointer"
> >
<Box <Text fontSize="lg" fontWeight="medium">
p={3} {item.label}
borderRadius="md" </Text>
_hover={{ bg: 'gray.100' }} </Box>
cursor="pointer"
>
<Text fontSize="lg" fontWeight="medium">
{item.label}
</Text>
</Box>
</Link>
))} ))}
</VStack> </VStack>
</DrawerBody> </DrawerBody>

View File

@@ -122,6 +122,7 @@ function Advantages() {
const isMainInView = useInView(mainRef, { once: true }); const isMainInView = useInView(mainRef, { once: true });
return ( return (
<MotionBox <MotionBox
id="advantages"
ref={mainRef} ref={mainRef}
position="relative" position="relative"
w="100%" w="100%"

View File

@@ -104,7 +104,7 @@ function Info() {
cursor="pointer" cursor="pointer"
onClick={() => setSelectedInfo(info.id)} onClick={() => setSelectedInfo(info.id)}
bg={selectedInfo === info.id ? '#3D6741' : '#BCBCBC'} bg={selectedInfo === info.id ? '#3D6741' : '#BCBCBC'}
border={selectedInfo === info.id ? "4px solid #99BF35" : "none"} border={selectedInfo === info.id ? { base: "1px solid #99BF35", sm: "1px solid #99BF35", md: "4px solid #99BF35", lg: "4px solid #99BF35", xl: "4px solid #99BF35" } : "none"}
borderRadius={{ base: '15px', sm: '15px', md: '18px', lg: '20px', xl: '20px' }} borderRadius={{ base: '15px', sm: '15px', md: '18px', lg: '20px', xl: '20px' }}
display="flex" display="flex"
alignItems="center" alignItems="center"

View File

@@ -108,6 +108,7 @@ function Truth() {
return ( return (
<MotionBox <MotionBox
id="truth"
ref={mainRef} ref={mainRef}
position="relative" position="relative"
w="100%" w="100%"
@@ -232,7 +233,7 @@ function Truth() {
> >
<Link href={image.link}> <Link href={image.link}>
<MotionImage src={image.image} cursor="pointer" fit={'contain'} <MotionImage src={image.image} cursor="pointer" fit={'contain'}
loading="lazy" loading="lazy"
initial={{ opacity: 0, scale: 0.9 }} initial={{ opacity: 0, scale: 0.9 }}
animate={isTitleInView ? { opacity: 1, scale: 1 } : { opacity: 0, scale: 0.9 }} animate={isTitleInView ? { opacity: 1, scale: 1 } : { opacity: 0, scale: 0.9 }}
transition={{ duration: 0.3, delay: 1.2 + index * 0.2, ease: "easeOut" }} transition={{ duration: 0.3, delay: 1.2 + index * 0.2, ease: "easeOut" }}