[miniProjects] 05_Blurry Loading

๋ณด๋ฆฌยท2023๋…„ 6์›” 16์ผ
0

miniProjects

๋ชฉ๋ก ๋ณด๊ธฐ
6/47

05_Blurry Loading

๐Ÿ’ป ์ฃผ์ œ : ํผ์„ผํŠธ๊ฐ€ 100๊นŒ์ง€ ์ฑ„์›Œ์ง€๋ฉด์„œ ํ๋ฆฟํ–ˆ๋˜ ๋ฐฐ๊ฒฝ์ด ์ ์  ์„ ๋ช…ํ•˜๊ฒŒ ๋ณ€ํ•จ.

const loadText = document.querySelector('.loading-text');
const bg = document.querySelector('.bg');

let load = 0;

// 0.03์ดˆ๋งˆ๋‹ค blurring ํ•จ์ˆ˜ ์‹คํ–‰
let int = setInterval(blurring, 30);

function blurring() {
  load++;
  if(load > 99) {
    clearInterval(int);
  }
  loadText.innerText = `${load}%`;
  // opacity ํˆฌ๋ช…๋„ ์กฐ์ ˆ์€ 1์—์„œ 0์œผ๋กœ ๊ฐ€์•ผํ•จ.(ํฌ๋ฏธ(1) -> ์„ ๋ช…(0))
  loadText.style.opacity = scale(load, 0, 100, 1, 0);
  bg.style.filter = `blur(${scale(load, 0, 100, 30, 0)}px)`;
}


// https://stackoverflow.com/questions/10756313/javascript-jquery-map-a-range-of-numbers-to-another-range-of-numbers
const scale = (number, inMin, inMax, outMin, outMax) => {
  return (number - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
}
profile
์ •์‹ ์ฐจ๋ ค ์ด ๊ฐ๋ฐ•ํ•œ ์„ธ์ƒ์†์—์„œ

0๊ฐœ์˜ ๋Œ“๊ธ€