Skip to content

Commit e5c4619

Browse files
committed
feat: [#89] logo animation when scrolling
1 parent d48962b commit e5c4619

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

src/components/logo/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import './styles.css';
22
import LOGO from './assets/cd-labs-logo.png';
33

4+
// --------------------------------------------------------------------------------
5+
46
export function buildMainLogo() {
57
const logoContainer = document.createElement('div');
68
const logoImg = document.createElement('img');
@@ -17,4 +19,17 @@ export function buildMainLogo() {
1719
logoContainer.appendChild(logoText);
1820

1921
return logoContainer;
22+
}
23+
24+
// --------------------------------------------------------------------------------
25+
26+
export function changeLogoOnScroll() {
27+
const logoContainer = document.querySelector('.main-logo') as HTMLElement;
28+
if (!logoContainer) return;
29+
30+
if (window.scrollY > 50) {
31+
logoContainer.classList.add('scrolled');
32+
} else {
33+
logoContainer.classList.remove('scrolled');
34+
}
2035
}

src/components/logo/styles.css

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
21
.main-logo {
32
position: fixed;
43
top: 40px;
54
left: 55px;
5+
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
66

77
img {
88
width: 95px;
99
height: 95px;
1010
image-rendering: pixelated;
11+
transition: width 0.3s, height 0.3s;
12+
}
13+
14+
img:hover {
15+
animation: rotate 0.5s steps(4) infinite;
1116
}
1217

1318
p {
@@ -17,5 +22,24 @@
1722
font-family: "Handjet", sans-serif;
1823
font-size: 2em;
1924
font-weight: 900;
25+
transition: opacity 0.3s;
2026
}
21-
}
27+
}
28+
29+
.main-logo.scrolled img {
30+
width: 60px;
31+
height: 60px;
32+
}
33+
34+
.main-logo.scrolled p {
35+
opacity: 0;
36+
pointer-events: none;
37+
}
38+
39+
40+
@keyframes rotate {
41+
100% {
42+
transform: rotate(360deg);
43+
}
44+
}
45+

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { buildMainLogo } from "./components/logo";
1+
import {buildMainLogo, changeLogoOnScroll} from "./components/logo";
22
import { router } from "./core/router";
33
import {homeView, buildViewBase, renderView} from "./views";
44
import {buildTopNav} from "./components/top-nav";
@@ -20,6 +20,8 @@ function init() {
2020

2121
body.appendChild(mainLogo);
2222
body.appendChild(nav);
23+
window.addEventListener('scroll', changeLogoOnScroll);
24+
2325
body.appendChild(contentPage);
2426

2527

0 commit comments

Comments
 (0)