Skip to content

Commit

Permalink
feat(mypage.jsx): main page animation comp
Browse files Browse the repository at this point in the history
  • Loading branch information
junglesub committed Aug 6, 2024
1 parent 9e337df commit 11fb2d9
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 21 deletions.
Binary file added public/assets/cups/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 0 additions & 4 deletions public/assets/cups/1.svg

This file was deleted.

42 changes: 42 additions & 0 deletions src/components/FloatingDiv.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React, { useState, useEffect } from "react";

const FloatingDiv = ({
children,
className = "",
style = {},
interval = 2000,
maxDistance = 50,
maxTilt = 10,
}) => {
const [transform, setTransform] = useState("");

useEffect(() => {
const animateDiv = () => {
const xMove = Math.random() * maxDistance * 1.4 - maxDistance;
const yMove = Math.random() * maxDistance * 2 - maxDistance;
const tilt = Math.random() * maxTilt * 2 - maxTilt;

setTransform(`translate(${xMove}px, ${yMove}px) rotate(${tilt}deg)`);
};

animateDiv(); // Initial animation
const intervalId = setInterval(animateDiv, interval);

return () => clearInterval(intervalId); // Cleanup on unmount
}, [interval, maxDistance, maxTilt]);

return (
<div
className={`floating-div ${className}`}
style={{
...style,
transform,
transition: `transform ${interval / 1000}s ease-in-out`,
}}
>
{children}
</div>
);
};

export default FloatingDiv;
6 changes: 5 additions & 1 deletion src/components/Mypage/GroupViewMain.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ import WaterDrinkSlider from "./WaterDrinkSlider";
import PeopleIcon from "src/assets/Mypage-group/peopleicon-black.svg";

import GroupRightArrow from "src/assets/Mypage-group/group-rightarrow-blue.svg";
import { FloatEffect } from "../../styles/FloatEffect";
import FloatingDiv from "../FloatingDiv";

function GroupViewMain({ groupData, groupMembers }) {
console.log({ groupMembers });
return (
<div>
<WoomoolCharImg src={WoomoolChar} />
<FloatingDiv maxDistance={10} maxTilt={5} interval={1000}>
<WoomoolCharImg src={WoomoolChar} />
</FloatingDiv>
<Total>
<div className="today">This Week</div>
<div>{convertMlToL(groupData.groupTotal)}L</div>
Expand Down
56 changes: 50 additions & 6 deletions src/components/Mypage/PersonalViewMain.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import TheButton from "src/styles/TheButton";
import { HoverImageSpan } from "../../styles/stylePresets";
import { useSetRecoilState } from "recoil";
import { userDetailAtom } from "../../recoil/userAtoms";
import { FloatEffect } from "../../styles/FloatEffect";
import FloatingDiv from "../FloatingDiv";

function PersonalViewMain() {
const fetchBe = useFetchBe();
Expand Down Expand Up @@ -73,9 +75,17 @@ function PersonalViewMain() {

return (
<>
<MainMugArea>
<img src={MainMug} />
</MainMugArea>
<FloatingDiv maxDistance={10} maxTilt={5} interval={1000}>
<MainMugArea>
<img src={`/assets/cups/1.png`} />
<div>
<TextDrank>
<div className="small">TODAY</div>
<div>1.5L</div>
</TextDrank>
</div>
</MainMugArea>
</FloatingDiv>

<WaterButtons>
<WaterButton onClick={() => sendWaterDrink("sip")}>
Expand Down Expand Up @@ -156,12 +166,32 @@ function PersonalViewMain() {
export default PersonalViewMain;

const MainMugArea = styled.div`
position: relative;
max-width: 380px;
text-align: center;
margin: auto;
margin-top: -20px;
margin-bottom: 54px;
transition: margin-bottom 300ms;
@media (max-width: 750px) {
margin-bottom: 20px;
}
img {
width: 100%;
}
& > div {
position: absolute;
bottom: 0;
top: 0;
right: 0;
left: 0;
margin: auto;
display: flex;
align-items: flex-end;
justify-content: center;
margin-left: 70px;
margin-bottom: 60px;
}
`;

const WaterButtons = styled.div`
Expand Down Expand Up @@ -206,9 +236,7 @@ const ModalContent = {
`,
header: styled.div`
${pretendard}
/* 무엇을 얼마나 마셨나요? */
font-style: normal;
font-style: normal;
font-weight: 700;
font-size: 28px;
line-height: 33px;
Expand Down Expand Up @@ -287,3 +315,19 @@ const CustomModalInput = styled.input`
outline: none;
}
`;

const TextDrank = styled.div`
${pretendard}
font-style: normal;
font-weight: 600;
font-size: 70px;
/* identical to box height */
text-align: center;
text-transform: uppercase;
.small {
font-size: 33px;
}
color: #000000;
`;
4 changes: 2 additions & 2 deletions src/pages/Mypage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ function Mypage() {
<>
<PersonalViewMain />
<TempText>
<div>
{/* <div>
Today <br />
{convertMlToL(userData.todayTotal)}L
</div>
</div> */}
</TempText>
</>
) : groupMode === 1 ? (
Expand Down
61 changes: 53 additions & 8 deletions src/pages/TestPage.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,58 @@
import React from "react";
import { NewContainer } from "../styles/Container";
import WaterDrinkSlider from "../components/Mypage/WaterDrinkSlider";
import React, { useEffect, useState } from "react";

function TestPage() {
const TestPage = () => {
return (
<NewContainer>
<WaterDrinkSlider />
</NewContainer>
<div className="TestPage">
<FloatingDiv
className="custom-class"
style={{ backgroundColor: "blue", width: "100px", height: "100px" }}
interval={3000}
maxDistance={75}
maxTilt={15}
>
<p>I'm floating!</p>
</FloatingDiv>
</div>
);
}
};

const FloatingDiv = ({
children,
className = "",
style = {},
interval = 600,
maxDistance = 50,
maxTilt = 10,
}) => {
const [transform, setTransform] = useState("");

useEffect(() => {
const animateDiv = () => {
const xMove = Math.random() * maxDistance * 2 - maxDistance;
const yMove = Math.random() * maxDistance * 2 - maxDistance;
const tilt = Math.random() * maxTilt * 2 - maxTilt;

setTransform(`translate(${xMove}px, ${yMove}px) rotate(${tilt}deg)`);
};

animateDiv(); // Initial animation
const intervalId = setInterval(animateDiv, interval);

return () => clearInterval(intervalId); // Cleanup on unmount
}, [interval, maxDistance, maxTilt]);

return (
<div
className={`floating-div ${className}`}
style={{
...style,
transform,
transition: `transform ${interval / 1000}s ease-in-out`,
}}
>
{children}
</div>
);
};

export default TestPage;
22 changes: 22 additions & 0 deletions src/styles/FloatEffect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { css } from "styled-components";

export const FloatEffect = css`
transition: transform 2s ease-in-out;
/* animation: float 2s ease-in-out infinite;
@keyframes float {
0%,
100% {
transform: translateY(0) rotate(0deg);
}
25% {
transform: translateY(-10px) rotate(-3deg);
}
50% {
transform: translateY(-20px) rotate(0deg);
}
75% {
transform: translateY(-10px) rotate(3deg);
}
} */
`;

0 comments on commit 11fb2d9

Please sign in to comment.