The code powering m.abunchtell.com https://m.abunchtell.com
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

37 linhas
840 B

  1. import { isMobile } from '../is_mobile';
  2. /** @type {number | null} */
  3. let cachedScrollbarWidth = null;
  4. /**
  5. * @return {number}
  6. */
  7. const getActualScrollbarWidth = () => {
  8. const outer = document.createElement('div');
  9. outer.style.visibility = 'hidden';
  10. outer.style.overflow = 'scroll';
  11. document.body.appendChild(outer);
  12. const inner = document.createElement('div');
  13. outer.appendChild(inner);
  14. const scrollbarWidth = outer.offsetWidth - inner.offsetWidth;
  15. outer.parentNode.removeChild(outer);
  16. return scrollbarWidth;
  17. };
  18. /**
  19. * @return {number}
  20. */
  21. export const getScrollbarWidth = () => {
  22. if (cachedScrollbarWidth !== null) {
  23. return cachedScrollbarWidth;
  24. }
  25. const scrollbarWidth = isMobile(window.innerWidth) ? 0 : getActualScrollbarWidth();
  26. cachedScrollbarWidth = scrollbarWidth;
  27. return scrollbarWidth;
  28. };