sass-site/source/assets/js/components/navigation.ts

27 lines
635 B
TypeScript
Raw Normal View History

2023-01-06 22:40:29 +01:00
// Documentation Nav Scroll
2023-06-19 23:55:26 +02:00
$(() => {
2023-01-06 22:40:29 +01:00
// Vars
2023-01-09 21:15:35 +01:00
const nav = $('.sl-c-list-navigation-wrapper');
const sticky = nav.offset();
2023-01-06 22:40:29 +01:00
// Added sticky class when window top is great than nav top
2023-03-08 22:14:25 +01:00
const stickyNav = () => {
2023-01-09 20:48:04 +01:00
if (
nav.length > 0 &&
sticky &&
($(window).scrollTop() ?? 0) >= sticky.top
) {
2023-01-09 20:10:02 +01:00
$('.sl-l-medium-holy-grail__body').addClass('sl-js-nav--is-sticky');
2023-01-06 22:40:29 +01:00
} else {
2023-01-09 20:10:02 +01:00
$('.sl-l-medium-holy-grail__body').removeClass('sl-js-nav--is-sticky');
2023-01-06 22:40:29 +01:00
}
2023-03-08 22:14:25 +01:00
};
2023-01-06 22:40:29 +01:00
2023-01-09 20:10:02 +01:00
// When scrolling the page, execute stickyNav
2023-06-19 23:55:26 +02:00
$(window).on('scroll', () => {
2023-01-09 20:10:02 +01:00
stickyNav();
});
2023-01-06 22:40:29 +01:00
return stickyNav();
});