๐Web Developing/Advanced-HTML, CSS, JS
[JS] ์ ์ฉํ ํจ์๋ค
Hush
2022. 6. 26. 10:46
setTimeout(Function, Delay);
Delay๋งํผ ๊ธฐ๋ค๋ฆฐ ํ Function์ ์คํํ๋ค.
Delay์๋ ์ซ์๋ง ์ ์ด์ฃผ๋ฉด ๋๋ฉฐ, ๋จ์๋ ms์ด๋ค.
์ฌ๊ทํจ์์ ์ฌ์ฉํ๋ฉด ์ผ์ ์๊ฐ์ด ์ง๋ ๋ ๋ง๋ค ์์ ์ ์ํํ๋ ๋ฐ์ ์ ์ฉํ๋ค.
๋ค์ ์ฝ๋๋ setTimeout์ ์ฌ์ฉํ์ฌ target ์์์ ํ ์คํธ๋ฅผ ํ๋์ฉ ๋ฃ์ด์ฃผ๋ ํจ์์ด๋ค.
function dynamic(randomArr){
if(randomArr.length>0){
target.textContent += randomArr.shift();
setTimeout(function(){
dynamic(randomArr);
}, 80);
}
}