Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const header = document.getElementById('floating-header');
- const title = document.getElementById('post-full-title');
- const eventParams = { passive: true };
- let lastScrollY = window.scrollY;
- let ticking = false;
- function requestTick() {
- if (ticking) return;
- requestAnimationFrame(update);
- ticking = true;
- }
- function update() {
- // show/hide floating header
- if (title.getBoundingClientRect().bottom < 0) {
- header.classList.add('floating-active');
- } else {
- header.classList.remove('floating-active');
- }
- ticking = false;
- }
- window.addEventListener('scroll', onScroll, eventParams);
- function onScroll() {
- lastScrollY = window.scrollY;
- requestTick();
- }
- window.addEventListener('resize', requestTick, eventParams);
- update();
Advertisement
Add Comment
Please, Sign In to add comment