RPeraltaJr
7/16/2019 - 6:51 PM

Prevent body scrolling while Lightbox is active

// * usage for general showing / hiding elements by modifying body classList
const lockBody = (option) => {
  if (option === true) {
    document.body.style.top = `-${window.scrollY}px`;
    document.body.style.position = 'fixed';
  } else {
    if (document.body.style.position !== 'fixed') return;
    const top = document.body.style.top;
    document.body.style.position = '';
    document.body.style.top = '';
    window.scrollTo(0, parseInt(top || '0', 10) * -1);
  }
};

// lockBody(true);