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,14 +151,9 @@ 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
key={index}
href={item.href}
onClick={() => setIsDrawerOpen(false)}
textDecoration="none"
_hover={{ textDecoration: 'none' }}
>
<Box <Box
key={index}
onClick={() => scrollToSection(item.id)}
p={3} p={3}
borderRadius="md" borderRadius="md"
_hover={{ bg: 'gray.100' }} _hover={{ bg: 'gray.100' }}
@@ -160,7 +163,6 @@ function Header({ showMenu = false }: HeaderProps) {
{item.label} {item.label}
</Text> </Text>
</Box> </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%"