Skip to content

Commit 7b4a454

Browse files
committed
expchart animations
1 parent b22c082 commit 7b4a454

File tree

4 files changed

+99
-10
lines changed

4 files changed

+99
-10
lines changed

Easings.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
POWER1, POWER2, POWER3, POWER4 from gsap:
2+
3+
Power1.easeOut:
4+
ease: [0.25, 0.1, 0.25, 1]
5+
6+
Power2.easeOut:
7+
ease: [0.25, 0.1, 0.25, 1]
8+
9+
Power3.easeOut:
10+
ease: [0.25, 0.1, 0.25, 1]
11+
12+
Power4.easeOut:
13+
ease: [0.25, 0.46, 0.45, 0.94]
14+
15+
OTHER TRANSITIONS TO TRY:
16+
17+
ease: [0.645, 0.045, 0.355, 1] (EaseInOutCubic)
18+
ease: [0.755, 0.05, 0.855, 0.06] (EaseInOutQuart)
19+
ease: [0.86, 0, 0.07, 1] (EaseInOutSine)
20+
ease: [0.95, 0.05, 0.795, 0.035] (EaseInOutQuint)
21+
ease: [0.6, 0.04, 0.98, 0.335] (EaseInOutExpo)
22+
23+
EaseInOut: [0.83, 0, 0.17, 1]
24+
EaseOutCubic: [0.215, 0.61, 0.355, 1]
25+
EaseInOutCubic: [0.645, 0.045, 0.355, 1]
26+
EaseOutQuart: [0.165, 0.84, 0.44, 1]
27+
EaseInOutQuart: [0.77, 0, 0.175, 1]

src/components/junior/ExpChart/ExpChart.css

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;700&display=swap');
1+
@import url("https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;700&display=swap");
22

33
.expChart {
44
min-height: 100vh;
5-
font-family: 'DM Sans', sans-serif;
5+
font-family: "DM Sans", sans-serif;
66
font-size: 18px;
77
background-color: hsl(27, 66%, 92%);
88
padding: 25px;
@@ -65,6 +65,8 @@
6565
color: hsl(25, 47%, 15%);
6666
display: flex;
6767
flex-direction: column;
68+
min-height: 442px;
69+
justify-content: space-between;
6870
}
6971

7072
.expChart-graph-title {
@@ -82,6 +84,7 @@
8284
display: grid;
8385
grid-template-columns: repeat(7, 1fr);
8486
column-gap: 20px;
87+
min-height: 220px;
8588
}
8689

8790
.expChart-graph-data-info {

src/components/junior/ExpChart/ExpChart.jsx

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React, {useEffect} from 'react'
22
import './ExpChart.css'
33
import logo from '../ExpChart/assets/expenses-chart-component-main/images/logo.svg'
44
import data from '../ExpChart/assets/expenses-chart-component-main/data.json'
5+
import { motion } from 'framer-motion'
6+
import { basicFadeUp2Profile, basicFadeUpProfile } from './animation'
57

68
const ExpChart = () => {
79

@@ -23,14 +25,44 @@ const ExpChart = () => {
2325
document.getElementById(highest).classList.add('expChart-graph-data-vis-highest')
2426
}
2527

28+
29+
30+
2631
useEffect(()=>{
2732
addStyle()
33+
34+
// ANIMATE COUNTER
35+
setTimeout(()=> {
36+
37+
const counters = document.querySelectorAll('.expChart-graph-stats-left-total');
38+
const speed = 700;
39+
40+
counters.forEach( counter => {
41+
const animate = () => {
42+
const value = +counter.getAttribute('counter');
43+
const data = +counter.innerText;
44+
45+
const time = value / speed;
46+
if(data < value) {
47+
counter.innerText = Math.ceil(data + time);
48+
setTimeout(animate, 1);
49+
}else{
50+
counter.innerText = `$${value}`;
51+
}
52+
53+
}
54+
55+
animate();
56+
});
57+
58+
},1200)
59+
2860
}, [])
2961

3062
return (
3163
<div className='expChart df'>
3264
<main className="expChart-container">
33-
<header className="expChart-header">
65+
<motion.header {...basicFadeUpProfile} className="expChart-header">
3466
<div className="expChart-balance-info">
3567
<h4 className="expChart-balance-info-title">
3668
My balance
@@ -40,17 +72,24 @@ const ExpChart = () => {
4072
</p>
4173
</div>
4274
<img src={logo} alt="" className="expChart-logo"/>
43-
</header>
44-
<section className="expChart-graph">
75+
</motion.header>
76+
<motion.section {...basicFadeUp2Profile} className="expChart-graph">
4577
<h1 className="expChart-graph-title">
4678
Spending - Last 7 days
4779
</h1>
4880
<ul className="expChart-graph-data-container">
4981
{data.map((item, index)=>(
5082
<li className="expChart-graph-data-info">
51-
<div className="expChart-graph-data-vis" key={index} id={index} style={{height:`${(Math.floor(item.amount)*3)}px`}}>
83+
<motion.div
84+
initial={{height:'0px'}}
85+
animate={{height:(Math.floor(item.amount)*3),
86+
transition:{duration: .2,
87+
ease:[0.25, 0.46, 0.45, 0.94],
88+
delay: 1.2+ (0.15 * index)
89+
}}}
90+
className="expChart-graph-data-vis" key={index} id={index} style={{height:`${(Math.floor(item.amount)*3)}px`}}>
5291
<span>${item.amount}</span>
53-
</div>
92+
</motion.div>
5493
<div className="expChart-graph-data-day">
5594
{item.day}
5695
</div>
@@ -62,8 +101,8 @@ const ExpChart = () => {
62101
<div className="expChart-graph-stats-left-desc">
63102
Total this month
64103
</div>
65-
<div className="expChart-graph-stats-left-total">
66-
$478.33
104+
<div className="expChart-graph-stats-left-total" counter="478.33">
105+
{/* $478.33 */}
67106
</div>
68107
</div>
69108
<div className="expChart-graph-stats-right">
@@ -75,7 +114,7 @@ const ExpChart = () => {
75114
</div>
76115
</div>
77116
</div>
78-
</section>
117+
</motion.section>
79118
</main>
80119
</div>
81120
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const ease = [0.25, 0.46, 0.45, 0.94]
2+
3+
export const basicFadeUpProfile = {
4+
initial:{opacity:0, y: 40},
5+
animate:{opacity:1, y: 0,
6+
transition: {
7+
delay: 0,
8+
ease: ease,
9+
duration: 1,
10+
}}
11+
}
12+
export const basicFadeUp2Profile = {
13+
initial:{opacity:0, y: 40},
14+
animate:{opacity:1, y: 0,
15+
transition: {
16+
delay: 0.4,
17+
ease: ease,
18+
duration: 1,
19+
}}
20+
}

0 commit comments

Comments
 (0)