Skip to content

Commit 7cba39a

Browse files
committed
New Pages Updates
-- Dynamic navbar color based on the scroll -- Dynamic height change when tab is changed
1 parent 7545809 commit 7cba39a

6 files changed

Lines changed: 77 additions & 18 deletions

File tree

dist/blog.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { initTabs } from './tabs.js';
1212
import { initAmplitude } from './tracking/amplitude.js';
1313
import { initCookie } from './tracking/cookie.js';
1414
import { initExperiment } from './tracking/experiment.js';
15+
import { initCheckSectionThemeScroll } from './scroll-themes.js';
1516

1617
$(document).ready(function () {
1718
initScrollToggle();
@@ -27,6 +28,7 @@ $(document).ready(function () {
2728
setupHookForFormSubmission();
2829
initExperiment();
2930
installAndScrollAnchorTags();
31+
initCheckSectionThemeScroll();
3032
});
3133

3234
$(document).ready(function () {

src/scroll-themes.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
export function initCheckSectionThemeScroll() {
2+
const navBarHeight = document.querySelector('[data-nav-bar-height]');
3+
const themeObserverOffset = navBarHeight ? navBarHeight.offsetHeight / 2 : 0;
4+
5+
function initializeAttributes() {
6+
const body = document.body;
7+
8+
if (!body.hasAttribute('data-theme-nav')) {
9+
body.setAttribute('data-theme-nav', 'light');
10+
}
11+
12+
const sections = document.querySelectorAll('section');
13+
sections.forEach(function (section) {
14+
if (!section.hasAttribute('data-theme-section')) {
15+
section.setAttribute('data-theme-section', 'light');
16+
}
17+
});
18+
}
19+
20+
function checkThemeSection() {
21+
const themeSections = document.querySelectorAll('[data-theme-section]');
22+
23+
themeSections.forEach(function (themeSection) {
24+
const rect = themeSection.getBoundingClientRect();
25+
const themeSectionTop = rect.top;
26+
const themeSectionBottom = rect.bottom;
27+
28+
if (themeSectionTop <= themeObserverOffset && themeSectionBottom >= themeObserverOffset) {
29+
const themeSectionActive = themeSection.getAttribute('data-theme-section');
30+
document.querySelectorAll('[data-theme-nav]').forEach(function (elem) {
31+
if (elem.getAttribute('data-theme-nav') !== themeSectionActive) {
32+
elem.setAttribute('data-theme-nav', themeSectionActive);
33+
}
34+
});
35+
}
36+
});
37+
}
38+
39+
function startThemeCheck() {
40+
document.addEventListener('scroll', checkThemeSection);
41+
}
42+
43+
initializeAttributes();
44+
checkThemeSection();
45+
startThemeCheck();
46+
}

src/tabs.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,29 +163,40 @@ export function initTabs() {
163163
$(this).addClass('is-active');
164164

165165
const index = $(this).closest('li').index();
166+
const currentHeight = $wrap.height();
166167

167168
$contents.each(function () {
168-
const $content = $(this);
169-
$content.hide();
169+
$(this).hide();
170170
});
171-
172171
$codes.hide();
173172

174173
const $targetContent = $contents.eq(index);
175174
const $targetCode = $codes.eq(index);
175+
176176
$targetContent.css('display', 'flex');
177+
$targetCode.css('display', 'flex');
178+
179+
const newHeight = $wrap.height();
180+
181+
$wrap.css('height', currentHeight);
182+
gsap.to($wrap, {
183+
height: newHeight,
184+
duration: 0.4,
185+
ease: 'power2.out',
186+
onComplete: () => {
187+
$wrap.css('height', 'auto');
188+
},
189+
});
177190

178191
if ($targetContent.is('ul, ol, li')) {
179192
const $items = $targetContent.find('li').add('[data-tabs="content-item"]');
180193
gsap.fromTo(
181194
$items,
182195
{ opacity: 0, y: 20 },
183-
{ opacity: 1, y: 0, duration: 0.4, stagger: 0.08, ease: 'power2.out' }
196+
{ opacity: 1, y: 0, duration: 0.4, stagger: 0.08, ease: 'power2.out', delay: 0.2 }
184197
);
185198
}
186199

187-
$targetCode.css('display', 'flex');
188-
189200
wrapTimeline = animateCode($targetCode);
190201
});
191202
});

0 commit comments

Comments
 (0)