27 lines
647 B
TypeScript
Raw Normal View History

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