Skip to content

Commit 8763298

Browse files
authored
Merge pull request #8 from mlutcss/feat/animated-logo
Animate logo in the header
2 parents 3ae1eb3 + dcc68cf commit 8763298

File tree

5 files changed

+44
-4
lines changed

5 files changed

+44
-4
lines changed

src/_includes/header/header.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<%# Logo %>
1414

1515
<div class="W40p md_W25p md_Flg0.25">
16-
<a href="/#hero-page" class="Mxw35u md_Mxw25u D">
16+
<a href="/#hero-page" id="header-logo" class="Mxw35u md_Mxw25u D <%= it.cssHeaderLogoVisibility %> Ts-O;$shortTs">
1717
<img class="D P1u;2u W70p sm_W85p md_W100p" alt="mlut logo" src="/assets/img/logo.png">
1818
</a>
1919
</div>

src/arts.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
layout: 'base.ejs'
3-
title: Arts
3+
area: Arts
44
---
55
<%
66
const artsPageCSS = {

src/assets/script/toggleLogo.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const hero = document.querySelector('#hero-page');
2+
const logo = document.querySelector('#header-logo');
3+
4+
function handleIntersect(entries, observer){
5+
entries.forEach(entry => {
6+
if (!entry.isIntersecting){
7+
logo.style.visibility = "visible";
8+
logo.style.opacity = 1;
9+
} else {
10+
logo.style.opacity = 0;
11+
setTimeout(() => {
12+
logo.style.visibility = "hidden";
13+
}, 200);
14+
};
15+
});
16+
};
17+
18+
function createObserver(){
19+
const options = {
20+
root: null,
21+
threshold: "0.15",
22+
rootMargin: "0px",
23+
};
24+
25+
const observer = new IntersectionObserver(handleIntersect, options);
26+
observer.observe(hero);
27+
};
28+
29+
createObserver();

src/index.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
layout: 'base.ejs'
3+
area: 'main'
34
---
45
<%
56
const sectionHeader = "Txa-c M0;0;5u Fns7u C-$accent900"

src/layouts/base.ejs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
<%
2+
let cssHeaderLogoVisibility = "Vs-v O1"
3+
if (it.area === "main"){
4+
cssHeaderLogoVisibility = "Vs-h O0"
5+
}
6+
7+
%>
8+
19
<!DOCTYPE html>
210
<html lang="en"
311
class="
@@ -14,8 +22,9 @@
1422
<title>mlut - make CSS exciting again!</title>
1523
</head>
1624
<body class="D-f Fld-c Jc-sb Fnf-sans-serif Bgc-$core950">
17-
18-
<%- include('../_includes/header/header.ejs') %>
25+
<%- include('../_includes/header/header.ejs',{
26+
cssHeaderLogoVisibility: cssHeaderLogoVisibility
27+
}) %>
1928
<main >
2029
<%- it.content %>
2130
</main>
@@ -24,5 +33,6 @@
2433

2534
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/highlight.min.js"></script>
2635
<script>hljs.highlightAll();</script>
36+
<script src="../assets/script/toggleLogo.js" type="module"></script>
2737
</body>
2838
</html>

0 commit comments

Comments
 (0)