All files / publisher/market stickyListingBar.js

20% Statements 2/10
0% Branches 0/2
0% Functions 0/4
22.22% Lines 2/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19    1x           1x                    
import throttle from "../../libs/throttle";
 
export const toggleClassWhenStickyOnTop = (el, className) => {
  if (el) {
    el.classList.toggle(className, el.getBoundingClientRect().top === 0);
  }
};
 
export const toggleShadowWhenSticky = (el) => {
  toggleClassWhenStickyOnTop(el, "sticky-shadow");
};
 
export default function () {
  const stickyBar = document.querySelector(".js-sticky-bar");
  toggleShadowWhenSticky(stickyBar);
  const onScroll = throttle(() => toggleShadowWhenSticky(stickyBar), 30);
  document.addEventListener("scroll", onScroll);
}