mobile inner height

๋ชจ๋ฐ”์ผ ํ™˜๊ฒฝ์—์„œ ์Šคํฌ๋ฆฐ ๋†’์ด๋ฅผ 100vh๋กœ ์„ค์ •ํ–ˆ์„ ๋•Œ, ์ƒ๊ฐ๊ณผ ๋‹ค๋ฅด๊ฒŒ ํ™”๋ฉด์— ์Šคํฌ๋กค์ด ์ƒ๊ธด๋‹ค. ๋ชจ๋ฐ”์ผ ๋ธŒ๋ผ์šฐ์ €์—์„œ๋Š” ํ•˜๋‹จ๋ฐ”์™€ ์ƒ๋‹จ๋ฐ” ๋†’์ด๊ฐ€ ๋”ํ•ด์ ธ์„œ ์Šคํฌ๋ฆฐ ๋†’์ด๊ฐ€ ํฌ๊ฒŒ ์žกํžŒ๋‹ค.

์‹ค์ œ ์Šคํฌ๋ฆฐ ๋†’์ด๋กœ 100vh ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•

javascript + css๋กœ ํ•ด๊ฒฐํ•˜๊ธฐ

let vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);
body {
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
}

react ์ฝ”๋“œ๋กœ ์ž‘์„ฑํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

  useEffect(() => {
    function setInnerHeight() {
      let vh = window.innerHeight * 0.01;
      document.documentElement.style.setProperty('--vh', `${vh}px`);
    }

    setInnerHeight();
    window.addEventListener('resize', setInnerHeight);
    return () => {
      window.removeEventListener('resize', setInnerHeight);
    };
  }, []);

Last updated