Skip to content

Commit 8fbad88

Browse files
committed
animation finished
1 parent 62bf99e commit 8fbad88

File tree

6 files changed

+160
-8
lines changed

6 files changed

+160
-8
lines changed

README.md

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ http://127.0.0.1:5173/
2222
8. [Custom Font](#custom-font)
2323
9. [Flex Box](#flex-box)
2424
10. [CSS Grid](#css-grid)
25-
11. [Other Resources](#resources-for-vite)
25+
11. [Transitions & Animations](#transitions--animations)
26+
12. [Other Resources](#resources-for-vite)
2627

2728
****
2829

@@ -244,6 +245,69 @@ font: font-style font-variant font-weight font-size/line-height font-family;
244245
![image](https://github.com/actionanand/css-uhost/assets/46064269/c7bd6b0d-7b48-487c-a376-a1a4ae50caa7)
245246

246247

248+
[🔼Back to the top](#contents)
249+
250+
## Transitions & Animations
251+
252+
* Simple animation
253+
254+
```css
255+
.modal {
256+
/* animation css - `ease-in` -> starts slower & ends faster; `ease-out` -> reverse of the prior*/
257+
opacity: 0;
258+
transform: translateY(-3rem);
259+
transition: opacity 200ms, transform .5s;
260+
}
261+
262+
.open {
263+
opacity: 1;
264+
transform: translateY(0);
265+
}
266+
```
267+
268+
```css
269+
transition: WHAT DURATION DELAY TIMING-FUNCTION;
270+
transition: opacity 200ms 1s ease-out;
271+
```
272+
273+
The above line can be translated to: "Animate any changes in the `opacity` property (for the element to which the `transition` property is applied) over a duration of **200ms**. Start fast and end slow, also make sure to wait **1s** before you start".
274+
275+
1. [transition-property](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-property)
276+
2. [transition-duration](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-duration)
277+
3. [transition-timing-function](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-timing-function)
278+
4. [transition-delay](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-delay)
279+
5. [MDN article on CSS transitions](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Transitions/Using_CSS_transitions)
280+
6. [Easing Functions Cheat Sheet](https://easings.net/)
281+
282+
```css
283+
animation: NAME DURATION DELAY TIMING-FUNCTION ITERATION DIRECTION FILL-MODE PLAY-STATE;
284+
animation: wiggle 200ms 1s ease-out 8 alternate forwards running;
285+
286+
@keyframes wiggle {
287+
from {
288+
transform: rotateZ(0);
289+
}
290+
to {
291+
transform: rotateZ(10deg);
292+
}
293+
}
294+
```
295+
296+
The above line Can be translated to: "Play the **wiggle keyframe** set (animation) over a duration of **200ms**. Between two keyframes **start fast and end slow**, also make sure to **wait 1s before you start**. Play **8 animations** and **alternate** after each animation. Once you're done, **keep the final value** applied to the element. Oh, and you should be **playing the animation - not pausing**."
297+
298+
1. [animation-name](https://developer.mozilla.org/en-US/docs/Web/CSS/animation-name)
299+
2. [animation-duration](https://developer.mozilla.org/en-US/docs/Web/CSS/animation-duration)
300+
3. [animation-timing-function](https://developer.mozilla.org/en-US/docs/Web/CSS/animation-timing-function)
301+
4. [animation-delay](https://developer.mozilla.org/en-US/docs/Web/CSS/animation-delay)
302+
5. [animation-iteration-count](https://developer.mozilla.org/en-US/docs/Web/CSS/animation-iteration-count)
303+
6. [animation-direction](https://developer.mozilla.org/en-US/docs/Web/CSS/animation-direction)
304+
7. [animation-fill-mode](https://developer.mozilla.org/en-US/docs/Web/CSS/animation-fill-mode)
305+
8. [animation-play-state](https://developer.mozilla.org/en-US/docs/Web/CSS/animation-play-state)
306+
9. [MDN article on CSS animations](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Animations/Using_CSS_animations)
307+
308+
* [List of "transitionable" Properties](https://www.w3.org/TR/css-transitions-1/#animatable-properties)
309+
310+
247311
[🔼Back to the top](#contents)
248312

249313
## Resources for Vite

pages/customers/customers.css

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ main {
5959
margin: .2rem;
6060
}
6161

62+
.testimonial:hover .testimonial__image-container {
63+
animation: flip-customer-mbl 1s ease-out forwards;
64+
}
65+
6266
@media (min-width: 40rem) {
6367
.testimonial {
6468
margin: 3rem auto;
@@ -95,4 +99,33 @@ main {
9599
*/
96100
width: 30%;
97101
}
102+
103+
.testimonial:hover .testimonial__image-container {
104+
animation: flip-customer 1s ease-out forwards;
105+
}
106+
}
107+
108+
109+
@keyframes flip-customer-mbl {
110+
0% {
111+
transform: rotateY(0);
112+
}
113+
50% {
114+
transform: rotateY(160deg);
115+
}
116+
100% {
117+
transform: rotateY(360deg);
118+
}
98119
}
120+
121+
@keyframes flip-customer {
122+
0% {
123+
transform: rotateY(0) skew(20deg);
124+
}
125+
50% {
126+
transform: rotateY(160deg) skew(20deg);
127+
}
128+
100% {
129+
transform: rotateY(360deg) skew(20deg);
130+
}
131+
}

pages/customers/customers.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ document.querySelector('#footer').innerHTML = htmlStrFooter;
5353
const toggleBtn = document.querySelector('.toggle-button');
5454
const mobileNav = document.querySelector('.mobile-nav');
5555
const backdrop = document.querySelector('.backdrop');
56+
const ctaBtn = document.querySelector('.main-nav__item--cta');
5657

5758
// & triggering mobile nav
5859
toggleBtn.addEventListener('click', () => {
@@ -64,3 +65,16 @@ backdrop.addEventListener('click', () => {
6465
mobileNav.classList.remove('open');
6566
backdrop.classList.remove('open');
6667
});
68+
69+
// js animation
70+
ctaBtn.addEventListener('animationstart', (event) => {
71+
console.log('Animation started : ', event);
72+
});
73+
74+
ctaBtn.addEventListener('animationend', (event) => {
75+
console.log('Animation ended : ', event);
76+
});
77+
78+
ctaBtn.addEventListener('animationiteration', (event) => {
79+
console.log('Animation iteration : ', event);
80+
});

pages/packages/packages.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ main {
2525
box-shadow: 2px 2px 4px rgba(0,0,0,0.5);
2626
border-color: #ff5454;
2727
/* border-color: #ff5454 !important; */
28+
animation: push-up 1s ease-out forwards;
2829
}
2930

3031
.package a {
@@ -120,3 +121,15 @@ main {
120121
border-right-color: #ff5454;
121122
}
122123
}
124+
125+
@keyframes push-up {
126+
0% {
127+
transform: translateY(0);
128+
}
129+
33% {
130+
transform: translateY(-1.5rem);
131+
}
132+
100% {
133+
transform: translateY(-1rem);
134+
}
135+
}

shared/css/modal.css

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
.modal {
22
position: fixed;
3-
display: none;
43
z-index: 200;
54
top: 20%;
65
left: 10%;
@@ -9,6 +8,15 @@
98
padding: 1rem;
109
border: 1px solid #ccc;
1110
box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5);
11+
/*
12+
display: none;
13+
*/
14+
/* animation css - `ease-in` -> starts slower & ends faster; `ease-out` -> reverse of the prior*/
15+
opacity: 0;
16+
transform: translateY(-3rem);
17+
transition: opacity 200ms ease-out, transform .5s cubic-bezier(0.87, 0, 0.13, 1);
18+
/* 3rd value `1s` is the delay -> transition: WHAT DURATION DELAY TIMING-FUNCTION; */
19+
/* transition: opacity 200ms ease-out 1s, transform .5s ease-out 1s; */
1220
}
1321

1422
.modal__title {
@@ -47,9 +55,6 @@
4755
border-color: #ff5454;
4856
}
4957

50-
.open {
51-
display: block;
52-
}
5358

5459
@media (min-width: 35rem) {
5560
.modal {

shared/css/shared.css

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ main {
3434
}
3535

3636
.backdrop {
37-
position: fixed;
3837
display: none;
38+
position: fixed;
3939
z-index: 100;
4040
width: 100vw;
4141
height: 100vh;
@@ -138,6 +138,11 @@ height: 100%;
138138
border-radius: 8px;
139139
}
140140

141+
.main-nav__item--cta {
142+
animation: wiggle 400ms 3s 8;
143+
/* animation-play-state: running; */
144+
}
145+
141146
.main-nav__item--cta a:hover,
142147
.main-nav__item--cta a:active,
143148
.mobile-nav__item--cta a:hover,
@@ -148,14 +153,17 @@ height: 100%;
148153
}
149154

150155
.mobile-nav {
151-
display: none;
152156
position: fixed;
153157
z-index: 101;
154158
top: 0;
155159
left: 0;
156160
background: white;
157161
width: 80%;
158162
height: 100vh;
163+
/* display: none; */
164+
/* Animation */
165+
transform: translateX(-100%);
166+
transition: transform 300ms ease-out;
159167
}
160168

161169
.mobile-nav__items {
@@ -232,7 +240,10 @@ height: 100%;
232240
}
233241

234242
.open {
235-
display: block;
243+
/* animation */
244+
display: block;
245+
opacity: 1;
246+
transform: translateY(0);
236247
}
237248

238249
@media (min-width: 40rem) {
@@ -260,3 +271,15 @@ height: 100%;
260271
margin: 0 1rem;
261272
}
262273
}
274+
275+
@keyframes wiggle {
276+
0% {
277+
transform: rotateZ(0);
278+
}
279+
50% {
280+
transform: rotateZ(-10deg);
281+
}
282+
100% {
283+
transform: rotateZ(10deg);
284+
}
285+
}

0 commit comments

Comments
 (0)