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;
}